Create Service Contract From WSDL

Topics: July and December Releases Forum
Jan 29, 2007 at 1:29 PM
I can't find the recipe 'Create Service Contract From WSDL' in my ServiceContracts project in my ASMX solution. Does it only work for WCF?
Jan 29, 2007 at 5:47 PM
Yes, this recipe is only available in the WCF guidance package.

Of course, there is nothing stopping anyone who needs this for ASMX to use the WCF recipe as a starting place and just build it. <wink/wink>

Hypothetically speaking, if anyone were to do this, I would be happy to post it on the site for the benefit of everyone else ;)

Mar 15, 2007 at 8:44 PM

I'm just wondering why the recipe to 'Create Service Contract From WSDL' doesn't allow you specify a static WSDL (a la WSCF from Thinktecture) file and seems rather to prefer a pointer to an existing web service or UDDI server (which may do the same thing when you get to that depending on which vendors UDDI server you are using).

If you are in the early stages of the act of creating a service it seems odd to be expected to already have an active service to reference.

Mar 16, 2007 at 7:21 PM

The Service address field in the *Add Service Reference& wizard does have support for WSDL files. You only need to do these two simple steps:
  1. Specify your address (file location) in the URI format like {file://C:/MySchemaFolder/MyService.wsdl}.
  2. Check inside your wsdl file that the location attribute in the address element points to this same location in #1:
<wsdl:port name="MyService" binding="tns:MyService">
      <soap:address location="file://C:/MySchemaFolder/MyService.wsdl" />

And you will follow the rest of the process as a normal service address.

Apr 20, 2007 at 4:18 PM
I used Charly's suggestion to try and use a file: WSDL with the "Create Service Contract From WSDL" wizard. The wizard gave the error "WSDL is improperly formed or does not have any valid contract". This same WSDL did however, work OK with the WSCF "Create Data Contract" wizard.

Here's the scenario: A solution architect has used some sort of WCF process to create a service contract project, and then he used svcutil.exe to generate a WSDL from it. He has given me the WSDL, and now my job is to use the WSDL as a starting point to create a service using Service Factory.

To help me troubleshoot this WSDL, does anyone have a reference WSDL that is known to be acceptable to the "Create Service Contract From WSDL" wizard?

Apr 23, 2007 at 6:12 PM
Simon sent me a wsdl that works in the "Create Service Contract From WSDL" wizard. I'll look at that for ideas. Also, another team member used svcutil to process my wsdl, and it output some more detailed error messages, which we are looking at now. Looks like problems with namespaces and file locations...

May 9, 2007 at 10:23 AM
I have exactly the same scenario and same problems. "Create Service Contract From WSDL" wizard doesn't like my wsdl's neither. If you can find a way to make it work, please let me know also.

It would be also interesting if you already found another way for creating a WCF service from wsdl's.
May 9, 2007 at 4:10 PM

We were finally successful in creating the service contract from WSDL. I made a few notes for my team to share my experience. Here they are.

The Process:

1. In Visual Studio, create a new solution using WSSF/WCF template. Open Visual Studio help and go to this link for instructions: Start of deleted content End of deleted content ms-help: //MS.VSCC.v80/MS.VSIPCC.v80/ms.wssf.2006Dec/WSSF/html/10-020-HowtoCreateVisualStudioSolutionsUsingtheWCFGuidancePackage.htm

2. Some WSDLs may not have a <wsdl:service> element. The wizard will need one (I think) in order to figure out what operations your service will include. If you don't have one, copy your wsdl and xsd files to a work folder, and add something like the following just before the final </wsdl:definitions> element of the wsdl. Select a binding from higher up in your WSDL that reflects what you want to do. Note that the <soap:address location> is the actual file name and path of the wsdl you are working on.

< wsdl:service name = " CrossReferenceService " >
< wsdl:port name = " CrossReference "
binding = " tns:DefaultBinding_CrossReference " >
< soap:address location = "file://c:/ " />
</ wsdl:port >
</ wsdl:service >

3. Make sure your WSDL has the <xsd:import schemaLocation> attribute set. Here's an example that assumes the wsdl and xsd files live in the same folder:

< xsd:import namespace = " " schemaLocation = " " />

4. Right-click on your Service Interfaces / ServiceContract project in Solution Explorer. Select "Service Factory (WCF)", then "Create Service Contract From WSDL". In the wizard, click the "..." for Web Service Address. In the Web Reference URL box, enter the file url of your wsdl as it appears in the <soap:address location> in step 2, and click Go. Hopefully you will see some web methods appear in the box below. Click "Add Reference" to dismiss the dialog. Back in the wizard, click in some other box to get the wizard to validate your wsdl choice. Hopefully you will not see the red circle with an exclamation point beside the name of your wsdl, and can finish the wizard.

5. If in step 4, you got the red circle thingy, you will be wanting some more clues right about now. Hover over the red circle to see a message. If that's not helpful, you can use svcutil.exe to try to get more clues. Open a Visual Studio console window and cd to a working folder that has your wsdl and related xsd files. Enter the command "svcutil *.wsdl *.xsd". You will either see it create a serialization file, or you will see some error messages that you can use to troubleshoot the wsdl.

6. Once you have the service contract created, you can finish off the process by creating and exposing the service interface. You are basically following the process in

ms-help: //MS.VSCC.v80/MS.VSIPCC.v80/ms.wssf.2006Dec/WSSF/html/12-000-CreatingaWCF_Service.htm

You will have to figure out how to incorporate steps such as the fault contracts, business entities, etc. You can probably add some of this stuff after you have generated the service contract, but before you create the service implementation.

Good luck!

May 9, 2007 at 9:00 PM
Very nice post Dale. Regarding your comment in #2, Some WSDLs may not have a <wsdl:service> element, I wonder if those wsdl are valid (conforms the spec) and in that case, then the recipe should consider that and does not reject the file or throw an exception.

May 9, 2007 at 11:18 PM

The WSDL I was working with came from another team member who was using a "code-based contract-first" approach. He used Visual Studio and WCF techniques to define his Data Contracts, Operations, and Interfaces in C# code. Then, he built his project, resulting in an assembly. Finally, he used svcutil.exe to extract the metadata from the assembly, resulting in the WSDL that came to me. In this case, the generated WSDL had no <wsdl:service> element. I don't know if that's the way it should be, but that's what happened.

About the ms-help links in the Process description I posted earlier:
due to some weird pasting error, any place that you see an embedded italic sub-string in the url, you need to add an underscore both before and after the italicized sub-string.