3

I've been given a WSDL file and several XSD files to build a web service for. Right now I'm trying to just get it setup to receive requests and respond.

My experience with WebServices is limited to the old asp version with an asmx file etc.

There is a lot of information in the XSD files, I don't want to build out the classes by hand, nor do I really understand exactly what that would entail anyways (I'd imagine just an xml serializable class but haven't looked into it).

Where do I start with this? I looked into WCF but its completely foreign to me so I'd kinda rather use the old style, but I'm struggling to find any info on how to set that up or get a head start with automated generation of classes from the XSD files.

I did try WCF a bit, but WSCF blue gives me errors (Cannot import wsdl:portType) when I try to generate the WebService code. And svcutil.exe will generate some of the XSD file info but not all of them for some reason.

So two questions:

  1. How can I generate some stub classes from XSD files to get this going

  2. A tutorial/walkthrough for generating a WCF service from a WSDL and multiple XSD files that does not use wscf blue?

Erwin Bolwidt
  • 30,799
  • 15
  • 56
  • 79
user2300846
  • 155
  • 2
  • 10

3 Answers3

5

Assuming you have a WSDL to start with, you can do the following. I did this when tasked with implementing an intermediate dispatch layer on top of an existing web service. The new service should expose the same interface as the original service but perform different functions internally. Note that I am talking about "classical" WCF services here (SOAP-based).

Step 1: Create code for the service interface from the WSDL

wsdl.exe /si /out:<targetfolder> <url-to-wsdl>

This generates a .cs file that contains the interfaces and additional data types (for transfer objects). Note that this file is not WCF-ready yet as wsdl.exe seems to assume you want to create an old .asmx service.

Step 2: Import interface code into your project

Add the generated file to your project. Add attributes for making the interfaces and their operations WCF-ready. You need to add [ServiceContract] to the interfaces and [OperationContract] to the operations.

Step 3: Create the WCF service

Create a WCF service (.svc file) and get rid of the generated interface. Instead, make the service implement the contract(s) from the generated interfaces. Now, you can implement the new functionality.

Step 4: Adjust the remaining binding, authentication settings etc. to match the original web service.

lzydrmr
  • 867
  • 5
  • 7
1

You can use the svcutil.exe to generate proxy .cs classes and app.config files for your client part of the service setup, from the wsdl and xsd files.

Following is a cmd that will will generate a proxy from the visual studio cmd line:

svcutil.exe c:\OutputFolder\ /o:serviceproxy.cs /config:app.config "C:\WSDL And XSD Folder\*.wsdl" "C:\WSDL And XSD Folder\*.xsd"
Pantelis
  • 2,060
  • 3
  • 25
  • 40
0

These might help you get started - if you plan to go the RESTful route:

http://www.codeproject.com/Articles/571813/A-Beginners-Tutorial-on-Creating-WCF-REST-Services

http://msdn.microsoft.com/en-us/library/bb412178.aspx

http://nareshkamuni.blogspot.com/2011/12/window-communication-foundation-wcf-in.html

More in depth - http://www.thatindigogirl.com/ - Michele Leroux Bustamante from a few years ago.

Not so much a walkthrough - but has good info http://rest.elkstein.org/2008/02/what-is-rest.html

Mike Weber
  • 311
  • 2
  • 16