title: Visual Studio 2013 error creating service data source with valid wsdl file
body: <p>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.</p>
  
  <p>For the most recent service I was only given a <a href="http://api.shipprimus.com/webservicesPrimus.wsdl" rel="nofollow noreferrer">link to a wsdl file</a>. I used wsdl-analyzer.com to validate the file which seems to be <a href="https://www.wsdl-analyzer.com/qualityReport/show/1236141927?version=1" rel="nofollow noreferrer">completely valid</a>. 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. </p>
  
  <pre><code>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:
  
  '&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
  &lt;!-- TYPES --&gt;
  &lt;wsdl:types&gt;
      &lt;xsd:schema targetNamespace="http://api.shipprimus.com"&gt;
          &lt;!-- GetRatesRequest --&gt;
          &lt;xsd:element name="GetRatesRequest"&gt;
              &lt;xsd:complexType&gt;
                  &lt;xsd:sequence&gt;     
                      &lt;xsd:element name="Username" type="xsd:string"/&gt;
                      &lt;xsd:element name="Password" type="xsd:string"/&gt;
                      &lt;xsd:element name="Carrier" minOccurs="0" type="xsd:string"/&gt;
                      &lt;xsd:element name="OriginZipCode" type="xsd:string"/&gt;
                      &lt;xsd:element '.
  
  If the service is defined in the current solution, try building the solution and adding the service reference again.
  </code></pre>
  
  <p>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.</p>
  
  <p>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 <a href="https://stackoverflow.com/questions/4304281/create-web-service-proxy-in-visual-studio-from-a-wsdl-file/14360303">this</a> 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. </p>
  
  <p>When I try adding the service using a local path to the downloaded WSDL file, as is suggested in the <a href="https://stackoverflow.com/a/14360303/3897302">answer receiving the bounty</a> for the question above, it still does not work albeit with a different error. </p>
  
  <pre><code>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:
  &lt;xsd:anotation xmlns:xsd='http://www.w3.org/2001/XMLSchema'&gt;..&lt;/xsd:anotation&gt;.
  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.
  </code></pre>
  
  <p>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 <code>&lt;xsd:anotation&gt;</code> element though.</p>
  
  <p>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.</p>
  
  <p>When I attempt to add the service as a Web Reference I get the following:</p>
  
  <p><img src="https://i.stack.imgur.com/6lrSi.png" alt="Primus Service as Web Reference Error"></p>
  
  <p>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. </p>
  
  <p>I decided to see if the service was even active using <a href="http://www.soapui.org/" rel="nofollow noreferrer">SoapUI</a> to connect to the service and it worked without any problems.</p>
  
  <p>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. </p>
  
  <hr>
  
  <p><strong>Important Edit</strong></p>
  
  <p>I have gotten the WSDL to import by changing the line in the Definitions element from what it is above to <code>xmlns:xsd="http://www.w3.org/2001/XMLSchema:annotation"</code> by simply adding ":annotation" to the end. </p>
  
  <p>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.</p>
  
  <hr>
  
  <p><strong>Attempting to run modified WSDL through SVCUtil.exe</strong></p>
  
  <p>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.</p>
  
  <pre><code>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.
  </code></pre>