106

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.

Community
  • 1
  • 1
Raha
  • 1,959
  • 3
  • 19
  • 28

5 Answers5

117

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.

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • I tried the same with svcutil, but didn't really succeed with faults. Do you maybe have some suggestions to my problem: http://goo.gl/dlen – Juri Mar 19 '10 at 09:16
  • 17
    "svcutil your.wsdl your.xsd" is what I needed for mine to work! thanks! – Tim Lewis Jan 24 '12 at 21:06
  • 3
    Check out this SO answer for info on downloading the wsdl and xsd in a format that svcutil will like. http://stackoverflow.com/questions/286657/what-is-the-best-way-to-download-all-of-the-wsdl-files-exposed-by-a-wcf-service – Brett Widmeier Jun 19 '12 at 14:50
  • @marc_s When I use this with my WSDL file, it seems to rename some elements in a very strange way, such that requests coming in to my server would not even be accepted. Is this normal? – Arj Jan 29 '16 at 12:21
  • @Arjun: no - this sounds like you need to put together all relevant facts, and **ask a question** on Stackoverflow ! :-) – marc_s Jan 29 '16 at 13:01
  • @marc_s Here's my question - not many views hence the desperation! http://stackoverflow.com/questions/35062506/wcf-service-svcutil-generating-unexpected-object-structure – Arj Jan 29 '16 at 14:09
42

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:

Cheeso
  • 189,189
  • 101
  • 473
  • 713
  • 3
    To anyone who follows the *Basic overview of WSDL-First* article: Take note of the comment that talks about `ReplyAction="*"`. It appears you need to get rid of that. There is a trail of explanations from that comment that gives the reasoning, but I haven't read it. – dan-gph Apr 06 '10 at 08:38
  • Links are dead now – K0D4 Sep 21 '20 at 15:02
  • 2
    New link to WSCF: https://github.com/WSCF/WSCF – Bob Lokerse Jan 26 '22 at 10:17
33

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.

sq33G
  • 3,320
  • 1
  • 23
  • 38
Dennis Calla
  • 839
  • 9
  • 10
  • See also: [MSDN on how to implement someone else's WSDL](https://msdn.microsoft.com/en-us/library/ms735109(v=vs.110).aspx) – sq33G Nov 14 '16 at 10:57
7

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.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
6

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.

Vagner Gon
  • 595
  • 9
  • 23