Create Service Contract From WSDL

Topics: July and December Releases Forum
Jan 29, 2007 at 12:29 PM
Hi,
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?
Coordinator
Jan 29, 2007 at 4: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 ;)

Don
Mar 15, 2007 at 7:44 PM
Hi,

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.

Simon.
Developer
Mar 16, 2007 at 6:21 PM
Simon,

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" />
</wsdl:port>

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

Charly
Apr 20, 2007 at 3: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?

Thanks,
Dale
Apr 23, 2007 at 5: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...

Dale
May 9, 2007 at 9:23 AM
Dale,
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.
Iyigun
May 9, 2007 at 3:10 PM
iyiguncevik,

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:/mycompany.com.schemas.2007Q2.Common.wsdl " />
</ 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 = " http://mycompany.com/schemas/2007Q2/Common " schemaLocation = "mycompany.com.schemas.2007Q2.Common.xsd " />

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!

Dale
Developer
May 9, 2007 at 8: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.

Thanks,
Charly
May 9, 2007 at 10:18 PM
Charly,

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.

Dale