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

WcfWsdl

Wcf Problem Overview


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.

Wcf Solutions


Solution 1 - Wcf

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.

Solution 2 - Wcf

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:

Solution 3 - Wcf

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.

Solution 4 - Wcf

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.

Solution 5 - Wcf

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRahaView Question on Stackoverflow
Solution 1 - Wcfmarc_sView Answer on Stackoverflow
Solution 2 - WcfCheesoView Answer on Stackoverflow
Solution 3 - WcfDennis CallaView Answer on Stackoverflow
Solution 4 - WcfJohn SaundersView Answer on Stackoverflow
Solution 5 - WcfVagner GonView Answer on Stackoverflow