How can I consume a WCF service using a local WSDL file? - wcf

I need to consume a WCF service based on a (preferably single) wsdl file.
The environment is VS-2008 (sp1), and I will be using a customized "Add Service Reference" macro to generate an error handling proxy. I want to be able to do this, by supplying a WSDL file that I get from the service provider (I do not want to supply a host URL).
How can this be done?

Sure - you can copy the path+filename for the WSDL and paste that into the "Add Service Reference" dialog box in Visual Studio (or just type int the full path + WSDL file name).
Alternatively, you can use the svcutil.exe command line utility to convert the WSDL file to your client proxy class.

Related

Using ChannelFactory with WorkflowServiceHost

Is there a way to do the service inference on a workflow definition XAML to create an interface that can be distributed to the client to be used with ChannelFactory instead of the host exposing WSDL and the client having to generate a service definition by adding a service reference?
I did this in a three step process:
Temporarily exposing the metadata from the workflow service
Creating proxy code with svcutil
Changing configuration back to not exposing metadata
In detail:
Include your XAMLX file which defines the service in a project that was created as "WCF Workflow Service Application" (DeclarativeServiceLibrary1)
Compile the project
Set the project as startup project
Select xamlx file in Solution Explorer
Press Ctrl-F5 -> WCF Test Client starts, you see your service loaded
RightClick on the xamlx URL in WCF Test Client, choose Copy address (e.g. http://localhost:56326/Service1.xamlx)
Open a VS2010 Admin console window
Create the proxy code with svcutil.exe:
cd /D %TEMP%
svcutil http://localhost:56326/Service1.xamlx
This creates two files, a *.cs and a *.config, that contain the proxy code
I had a lot of problems with other ways of craeting the proxy code (inside VS2010), the external svcutil was the most stable way to do it. Hope this helps.

Auto-generated WCF proxy class renames request/response classes

I am using Visual Studio 2008 to generate a WCF proxy class for an ASMX service I want to consume.
I have tried using both 'Add Service Reference' is VS and the command line svcutil.exe to generate a proxy from the ASMX service WSDL, but each time it creates an duplicate service method (for each operation) with different request and response classes (that have the digit '1' appended to the end the names).
Does anyone know how to stop WCF creating these duplicate methods with the request/response class names having the digit '1' appended to them?
Many thanks!
In your project folder you might have either of the folders 'ServiceReferences' or 'WebReferences'. Look inside these. If they have any folder of the same name as your service reference delete it. Now add the service reference again. It should work.

.net-WCF How do we create a client programatically?

How do I create a client programatically?
Open Visual Studio command prompt and move to client application folder using change directory command and type
svcutil.exe http://your_service_url/your_service_name.svc?wsdl
This will generate a configuration file (output.config) and a client class.
Client class name will be your_service_nameClient
Next you need to copy the <system.serviceModel> section from output.config to your App/Web config. Now your client application is ready to consume the service.
You can create client class object and invoke service methods.
Hope this will help you
You'll need to start the svcutil.exe process -- it could be done from a program, but it will generate source code, not binary code.
If you are new to WCF check out this site:
http://msdn.microsoft.com/en-us/netframework/dd939784.aspx
If you are only interested in learning how to create a client, this is the video for you:
http://channel9.msdn.com/shows/Endpoint/Endpoint-Screencasts-Creating-Your-First-WCF-Client/

wcf metadata service page url

I have a service with the metadata exposed. Trouble is when I browse to the wsdl the service page it has the machine name as below:
MasterLibrary Service
You have created a service.
To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:
svcutil.exe http://mymachine/Master/Master.svc?wsdl
How do I make it show it as:
http://www.url.co.uk/Master/Master.svc?wsdl
You can query your current site bindings for the default web site as following:
cscript //nologo %systemdrive%\inetpub\adminscripts\adsutil.vbs get W3SVC/1/ServerBindings
Here is the command to change it:
cscript //nologo %systemdrive%\inetpub\adminscripts\adsutil.vbs set W3SVC/1/ServerBindings “:80:www.fancydomain.com”
You can also change it from IIS Manager UI. For HTTPS, the following command would work:
cscript //nologo %systemdrive%\inetpub\adminscripts\adsutil.vbs set W3SVC/1/SecureBindings “:443:www.fancydomain.com”
2) Recycle the AppDomain
Once you changed IIS settings, WCF does not automatically pick up the changes from IIS Metabase. You have to recycle the current AppDomain for the virtual application. There are a few different ways to do that:
· Change web.config file for the virtual application
· Kill w3wp.exe process
· Run “iisreset.exe”
3) Query the WSDL
If using iis7 in server 2008 just right click the service in iismanager select edit bindings if its http, then edit the http binding. In the hostname dialog box enter your custom hostname.
This link talks more about it metadataservice

How to use a WSDL file to create a WCF service (not make a call)

I have an old WSDL file and I want to create a server based on this WSDL file.
The WSDL is generated from a ASMX (I suppose but I am not sure).
How can I achieve this ?
original question where the OP thought he needed to create a client based on the WSDL.
Using svcutil, you can create interfaces and classes (data contracts) from the WSDL.
svcutil your.wsdl (or svcutil your.wsdl /l:vb if you want Visual Basic)
This will create a file called "your.cs" in C# (or "your.vb" in VB.NET) which contains all the necessary items.
Now, you need to create a class "MyService" which will implement the service interface (IServiceInterface) - or the several service interfaces - and this is your server instance.
Now a class by itself doesn't really help yet - you'll need to host the service somewhere. You need to either create your own ServiceHost instance which hosts the service, configure endpoints and so forth - or you can host your service inside IIS.
There are good resources out there if you know what to search for. Try "Contract First" and WCF. or "WSDL First" and WCF.
Here is a selection:
Basic overview of WSDL-First development with WCF and SvcUtil.exe.
WSCF - A free add-in to Visual Studio enabling Contract-First design with WCF
Introduction to WSCF
A walkthrough of using WSCF
The WSCF project page on CodePlex (WSCF is now open source)
Article on how to design "WCF-Friendly" WSDL
Use svcutil.exe with the /sc switch to generate the WCF contracts. This will create a code file that you can add to your project. It will contain all interfaces and data types you need to create your service. Change the output location using the /o switch, or you can find the file in the folder where you ran svcutil.exe. The default language is C# but I think (I've never tried it) you should be able to change this using /l:vb.
svcutil /sc "WSDL file path"
If your WSDL has any supporting XSD files pass those in as arguments after the WSDL.
svcutil /sc "WSDL file path" "XSD 1 file path" "XSD 2 file path" ... "XSD n file path"
Then create a new class that is your service and implement the contract interface you just created.
You could use svcutil.exe to generate client code. This would include the definition of the service contract and any data contracts and fault contracts required.
Then, simply delete the client code: classes that implement the service contracts. You'll then need to implement them yourself, in your service.
Using the "Add Service Reference" tool in Visual Studio, you can insert the address as:
file:///path/to/wsdl/file.wsdl
And it will load properly.