2

I have been writing a project to use several different web services for getting shipping quotes. For the first two services, I had no problem adding them as a service data source by providing the url of the .asmx file for the service.

For the most recent service I was only given a link to a wsdl file. I used wsdl-analyzer.com to validate the file which seems to be completely valid. The WSDL fails with the below error message when I attempt to add it to the Visual Studio project as a service data source though.

There was an error downloading 'http://api.shipprimus.com/webservicesPrimus.wsdl/_vti_bin/ListData.svc/$metadata'.

The request failed with HTTP status 404: Not Found.

Metadata contains a reference that cannot be resolved: 'http://api.shipprimus.com/webservicesPrimus.wsdl'.

The content type text/plain of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. 

The first 1024 bytes of the response were:

'<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:tns="http://api.shipprimus.com" xmlns:xsd1="http://api.shipprimus.com" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"  targetNamespace="http://api.shipprimus.com">
<!-- TYPES -->
<wsdl:types>
    <xsd:schema targetNamespace="http://api.shipprimus.com">
        <!-- GetRatesRequest -->
        <xsd:element name="GetRatesRequest">
            <xsd:complexType>
                <xsd:sequence>     
                    <xsd:element name="Username" type="xsd:string"/>
                    <xsd:element name="Password" type="xsd:string"/>
                    <xsd:element name="Carrier" minOccurs="0" type="xsd:string"/>
                    <xsd:element name="OriginZipCode" type="xsd:string"/>
                    <xsd:element '.

If the service is defined in the current solution, try building the solution and adding the service reference again.

The first step I tried was to contact the company offering the service and ask if they could help, but they do not use Visual Studio, so they were of no help trying to add a Visual Studio service.

I then began to look around to see if there were other ways to possibly add the service from what I was given. I found this question, which is similar, but not exactly the same. There are several other questions regarding WSDL files and adding services to Visual Studio, but none of them have helped me.

When I try adding the service using a local path to the downloaded WSDL file, as is suggested in the answer receiving the bounty for the question above, it still does not work albeit with a different error.

The document at the url file:///C:/Users/isellar/Downloads/webservicesPrimus.wsdl was not recognized as a known document type.
The error message from each known type may help you fix the problem:

- Report from 'WSDL Document' is 'There is an error in XML document (364, 19).'.
- The element was not expected in this context:
<xsd:anotation xmlns:xsd='http://www.w3.org/2001/XMLSchema'>..</xsd:anotation>.
Expected elements: http://www.w3.org/2001/XMLSchema:annotation.
If the service is defined in the current solution, try building the solution and adding the service reference again.

It references what I assume to be a line number although I am not particularly familiar with the output of 'WSDL Document' whatever that is. Neither line 364 nor line 19 of the file has an <xsd:anotation> element though.

I also tried running the file through WSDL.exe as another answer from the above question suggests. With that I got a similar error to the one I received from Visual Studio. I assume Visual Studio just uses the WSDL.exe to process WSDL files since the outputs were almost identical and WSDL.exe is found under Visual Studio in Program Files.

When I attempt to add the service as a Web Reference I get the following:

Primus Service as Web Reference Error

As you can see it correctly grabs the method signatures from the WSDL but claims to have failed with a 404 and not found anything for a different metadata file.

I decided to see if the service was even active using SoapUI to connect to the service and it worked without any problems.

I am hoping that there is an easy way to fix the WSDL file so Visual Studio can simply import the service to my project as I have done with the other services.


Important Edit

I have gotten the WSDL to import by changing the line in the Definitions element from what it is above to xmlns:xsd="http://www.w3.org/2001/XMLSchema:annotation" by simply adding ":annotation" to the end.

This caused the WSDL to import, but with no generated code in the Reference.cs, I feel so very close to solving this, but yet so far away. I am still hoping that there is a simple change where I can get the WSDL to create a service reference correctly and the Reference code to generate for me as I spent a while already trying to write the code myself in the file without realizing that it would all be erased when Visual Studio tried to (incorrectly) regenerate the code.


Attempting to run modified WSDL through SVCUtil.exe

I attempted first to run the WSDL through svcutil per Leandros answer since I did not have access to an SVC file for the service. The first run received the same error message as the second code box above. I tried also to run with the modified WSDL that initially imported, but did not generate code from just above. This gave me the below error.

Error: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Schema with target namespace 'http://api.shipprimus.com' could not be found.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://api.shipprimus.com']/wsdl:portType[@name='WebservicePrimusServicePort']


Error: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='http://api.shipprimus.com']/wsdl:portType[@name='WebservicePrimusServicePort']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://api.shipprimus.com']/wsdl:binding[@name='WebservicePrimusSoapBinding']


Error: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on. XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://api.shipprimus.com']/wsdl:binding[@name='WebservicePrimusSoapBinding']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://api.shipprimus.com']/wsdl:service[@name='WebservicePrimus']/wsdl:port[@name='WebservicePrimusServicePort']


Generating files...
Warning: No code was generated.
If you were trying to generate a client, this could be because the metadata documents did not contain any valid contracts or services or because all contracts/services were discovered to exist in /reference assemblies. Verify that you passed all the meta data documents to the tool.

Warning: If you would like to generate data contracts from schemas make sure to use the /dataContractOnly option.
Community
  • 1
  • 1
Spaceman Spiff
  • 934
  • 1
  • 14
  • 32
  • Did you trying generating the code with svcutils? – Leandro Bardelli Nov 02 '14 at 01:52
  • 1
    A [similar question](http://stackoverflow.com/questions/5233380/why-cant-i-generate-client-code-from-this-wsdl-file-in-visual-studio). – Spaceman Spiff Nov 04 '14 at 16:08
  • 1
    Get a copy of SOAP UI and point it at the WSDL. I would suggest you run WSI Compliance test on the WSDL seems like the name spaces are messed up. SOAP UI is a must have to test a WSDL. – Namphibian Nov 04 '14 at 22:55
  • I did briefly mention that I had used SoapUI for this. I just ran WS-I compliance on the WSDL and it seems to have passed without any issue. – Spaceman Spiff Nov 04 '14 at 23:21

2 Answers2

4

This is fairly trivial, the .wsdl file on the web IS invalid, as it contains some illegal elements, ie a typo on <xsd:anotation>. Thus the xsd schema defining the types is being rejected.

To fix

  1. Download the webservicesPrimus.wsdl file locally as specified in the prior solution
  2. Do a global search and replace of xsd:anotation with xsd:annotation
  3. Add that updated file as a service reference, you'll get a fully populated References.cs
  4. As a courtesy contact the owner of the webService and point out the error.
tolanj
  • 3,651
  • 16
  • 30
  • Wow, was not expecting this. I suppose I should have examined the file a little more closely. – Spaceman Spiff Nov 06 '14 at 15:22
  • @Ian Sellar the error message from accessing the wsdl online was fairly inscrutable, which is its own kettle of fish. – tolanj Nov 06 '14 at 15:32
  • Very much so, I think that is what threw me off. Before your solution we were trying to get the provider to update their content for the file from text/html to application/soap+xml to see if that would help. – Spaceman Spiff Nov 06 '14 at 15:35
1

I had a lot of issues with contracts, references and services created by third companies. They are related often with infraestructure problems but I discover that some many times that problems impact without knowdledge of the infra's team in code and configuration itself.

I can think in many task to perform some checks and tries, I'll post two of them but if you can give me some results about them, we can improve to get a solution. So do not take this a final answer, I just want to help first and make a complex diagnostic.

First attempt to solution:

First of all, personally I shouldn't assume that the contract is valid, even if the services works in SOAPUI. By your update, you can do something like:

Create a reference to the service as old school. http://msdn.microsoft.com/es-es/library/aa347733%28v=vs.110%29.aspx

  1. Open the "Development Visual Studio tool" that is like a command-line application like node-js.
  2. Create a folder with "mkdir test" in anywhere you want
  3. Run

svcutil.exe http:// url-of-service /service.svc

If it can connect, it will create at least two files: One .cs that is the code you must map, and the second one is a .config file to attach the service in your app/web.config So you have everything you need at code level to start work.

If it can NOT connect, then there is another problem, related to the svc itself.

Second attempt to solution:

What is about the config file? What about the network? I saw too many times closed connections before time by some weird rules in servers.

Third attemp to solution:

Could SOAP UI generates a new contract as it uses for you can use it? I don't know if can explain myself. If SOAP UI works fine, could it give you the contract that uses? Is probable that SOAP UI are auto-correcting something without notice.


Did you discard networking/service problems at all?

Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
  • 1
    The only problem is that I don't have access to an svc file, all I have access to is the WSDL that I mentioned above. You can easily retrace the steps I have gone through by trying to import the wsdl yourself using the link provided in the beginning of the question. I just tried running the WSDL through the svcutil program and I got the same error message from the second box of the question. – Spaceman Spiff Nov 04 '14 at 15:30
  • 1
    When I tried running it with the modified wsdl that originally imported I got a new error that has now been added to the answer. – Spaceman Spiff Nov 04 '14 at 15:31
  • Mmmmm I'll try to generate it from here. In the middletime I suggest try to contact the responsible of the service, I don't think this is working properly. – Leandro Bardelli Nov 04 '14 at 15:33
  • @IanSellar I tried with every option that I know and I don't wanna be pretencious but I don't think any other option will made other response, I'm afraid that the service is wrong, or at least the contract. The more detailed response that I get said that the XML is not well formatted, and the schema is wrong. (like your answer) – Leandro Bardelli Nov 04 '14 at 16:38
  • 1
    Ok thanks for trying, I am going to contact the people in charge of the service and see if I can get anymore information. – Spaceman Spiff Nov 04 '14 at 16:40
  • Np, If you can get information or the service is redeployed and you still can't connect with some other error, please update your question and comment – Leandro Bardelli Nov 04 '14 at 16:46
  • I just think in a third idea... in order to avoid the tech conflict ( I know how they are) – Leandro Bardelli Nov 05 '14 at 16:15
  • I did look into that, unfortunately the tool that SoapUI uses to generate C# code is the same one that Visual Studio uses so it came up with the exact same errors. I am currently looking to see if I can get the code to generate for a different language through SoapUI – Spaceman Spiff Nov 05 '14 at 16:53
  • 1
    It seems to have generated just fine in java using Axis2. We may simply use this to avoid the hassle of writing the XML serialization by hand. – Spaceman Spiff Nov 05 '14 at 16:59