How to generate service reference with only physical wsdl file
Asked Answered
M

3

145

I have been creating and consuming web services for years and always have been able to use Visual Studio to create a service reference from the client. I have a third party service I need to work with and they refuse to open their security so I can see the wsdl and make the service reference. It's a public facing service so I don't see the need for that level of security but it is what it is.

I know this is a n00b question and I'm ashamed to be asking it, but how do I do create the equivalent Service Reference information in my client when all I have available to me is a physical copy of the wsdl the client emailed me? The web.config changes, the object layer over the SOAP data, etc. Just like with an automated Service Reference I just want to open a connection to the service and start using it with the defined objects.

The third party service is not WCF as far as I can tell but is SOAP. I'm using VS 2010.

Macaroni answered 3/10, 2012 at 14:7 Comment(1)
possible duplicate of Create web service proxy in Visual Studio from a WSDL filePeristalsis
A
208

This may be the easiest method

  • Right click on the project and select "Add Service Reference..."
  • In the Address: box, enter the physical path (C:\test\project....) of the downloaded/Modified wsdl.
  • Hit Go
Atalee answered 4/10, 2012 at 16:7 Comment(3)
If you use "Copy as Path" take off the quotes.Hispanicism
When saving the wsdl to pass along to someone else, "view source" of the wsdl from the webservice in chrome gave me a working wsdl, whereas IE11 did not. YMMV.Surgeonfish
also remember to dont have too long paths, since it wont import then.Ridgway
R
90

There are two ways to go about this. You can either use the IDE to generate a WSDL, or you can do it via the command line.

1. To create it via the IDE:

In the solution explorer pane, right click on the project that you would like to add the Service to:

enter image description here

Then, you can enter the path to your service WSDL and hit go:

enter image description here

2. To create it via the command line:

Open a VS 2010 Command Prompt (Programs -> Visual Studio 2010 -> Visual Studio Tools)
Then execute:

WSDL /verbose C:\path\to\wsdl

WSDL.exe will then output a .cs file for your consumption.

If you have other dependencies that you received with the file, such as xsd's, add those to the argument list:

WSDL /verbose C:\path\to\wsdl C:\path\to\some\xsd C:\path\to\some\xsd

If you need VB output, use /language:VB in addition to the /verbose.

Rident answered 3/10, 2012 at 14:11 Comment(7)
I get 'Unable to import binding 'blah' from namespace 'blahURL' and Unable to import operation 'SomeRequest', The element 'xxx' is missing. Does this mean they need to give me some more support files, or that they have their security so freakin locked down that I can't do anything?Macaroni
It certainly sounds like you're missing dependencies. Open the WSDL and look at the top. If you see lines that have an import in them followed by a schemaLocation that points to an xsd path, you'll need those xsd files as well.Rident
Thanks for response. I have an outstanding email with client to see if I can get the necessary xsd imports. It is so frustrating though, when done right I just pop a URL into ServiceReference dialog, push a button and viola! I'm about 3 lines of code away from calling a service method. The whole process takes about 5 minutes. But I've been working with this client for weeks and have gotten no where all because their security folks won't open up access to any service definitions via the web.Macaroni
That's rough. I'm currently waiting on a vpn connection for a project, myself. Fortunately, they gave me the wsdl and accompanying xsd docs ahead of time. So you did find those imports in the wsdl?Rident
Yes. Turns out for 4 services they gave me wsdl's for 2 of them and xsd's for the other 2 so no complete set of files for any of the services. But I finally got xsd's and was able to generate .cs files for 2 of the services, the other 2 will follow I assume. Thanks.Macaroni
Would you mind to clarify how to set properly reference to the local XSD file in the schemaLocation of the WSDL, please?Persuade
No worries I found an answer and put it here #19253902Persuade
S
4

Predecessors show how to import from local file but there's small chances that your WSDL will have one or more XSD referenced and you will receive error:

WSDL Reference Error

You will have to download all referenced XSD files, and put those into the same directory as referenced WSDL. Then you will have to manually edit WSDL, and change schemaLocation to local downloaded files.

Before

  <wsdl:types>
    <xsd:schema targetNamespace="http://tempuri.org/Imports">
      <xsd:import schemaLocation="http://gate.somesite.local:8084/Shop/SomeService.svc?xsd=xsd0" namespace="http://tempuri.org/" />
      <xsd:import schemaLocation="http://gate.somesite.local:8084/Shop/SomeService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
      <xsd:import schemaLocation="http://gate.somesite.local:8084/Shop/SomeService.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
    </xsd:schema>
  </wsdl:types>

After

  <wsdl:types>
    <xsd:schema targetNamespace="http://tempuri.org/Imports">
      <xsd:import schemaLocation="tempuri.org.xsd" namespace="http://tempuri.org/" />
      <xsd:import schemaLocation="schemas.microsoft.com.2003.10.Serialization.xsd" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
      <xsd:import schemaLocation="schemas.microsoft.com.2003.10.Serialization.Arrays.xsd" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
    </xsd:schema>
  </wsdl:types>

Beware there's posibility that those downloaded XSD files will have reference to web adresses as well.

Like this:

Before

<xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/DaxServiceLibrary.Messages" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/DaxServiceLibrary.Messages" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import schemaLocation="http://gate.somesite.local:8084/Shop/DaxService.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />

After

<xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/DaxServiceLibrary.Messages" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/DaxServiceLibrary.Messages" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:import schemaLocation="schemas.microsoft.com.2003.10.Serialization.Arrays.xsd" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
Stet answered 30/11, 2021 at 7:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.