无法在VS2010中使用WSDL

时间:2011-03-24 15:56:04

标签: c# soap wsdl

我试图在VS2010中使用以下WSDL,并且我遇到了似乎特定于WSDL的错误。

我将它添加为Web服务引用,并且最初没有创建代理类或任何内容 - 向导成功完成,我在项目中的〜/ Web References /下获得.wsdl和Reference.map文件,但是该服务在代码中不可用。

如果我在其上执行“更新Web引用”,则会收到以下错误:

Custom tool error: Unable to import WebService/Schema. The element attribute is not allowed on encoded message parts. The erroneous part is named 'textReturnObject' in message 'singleTextResponse'. (File: Reference.map line 1 column 1)

如果我尝试将“element”重命名为“type”,我会收到大量其他问题:

The custom tool 'MSDiscoCodeGenerator' failed.  Cannot find definition for http://schemas.xmlsoap.org/wsdl/:exampleServiceNameBinding.  Service Description with namespace http://schemas.xmlsoap.org/wsdl/ is missing.
Parameter name: name

有人能说清楚吗?我已经把WSDL放到了一些在线工具中并且它们很好地使用它 - VS2010是否存在某些类型的WSDL问题?

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.example.com/exampleServiceName" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/" name="exampleServiceName" targetNamespace="http://www.example.com/exampleServiceName" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <xsd:complexType name="exampleType">
    <sequence>
      <element minOccurs="1" maxOccurs="1" name="title" type="string" />
      <element minOccurs="1" maxOccurs="1" name="url" type="string" />
      <element minOccurs="1" maxOccurs="1" name="description" type="string" />
    </sequence>
  </xsd:complexType>
  <wsdl:types />
  <wsdl:message name="singleTextRequest">
    <wsdl:part name="intIdentity" type="xsd:integer" />
  </wsdl:message>
  <wsdl:message name="singleTextResponse">
    <wsdl:part name="textReturnObject" element="wsdl:exampleType" />
  </wsdl:message>
  <wsdl:portType name="exampleServiceNamePortType">
    <wsdl:operation name="singleTextAdvert">
      <wsdl:input message="tns:singleTextRequest" />
      <wsdl:output message="tns:singleTextResponse" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="exampleServiceNameBinding" type="tns:exampleServiceNamePortType">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc" />
    <wsdl:operation name="singleText">
      <soap:operation soapAction="urn:xmethods-delayed-quotes#singleText" />
      <wsdl:input>
        <soap:body use="encoded" namespace="urn:xmethods-delayed-quotes" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="encoded" namespace="urn:xmethods-delayed-quotes" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="exampleServiceNameService">
    <wsdl:port name="exampleServiceNamePort" binding="wsdl:exampleServiceNameBinding">
      <soap:address location="http://www.example.com/exampleServiceName/Server.php" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

2 个答案:

答案 0 :(得分:3)

我在SO上有一个问题,我在添加服务引用时遇到了问题。我最终按照建议使用了svcutil,它解决了这个问题。我的情况略有不同,但值得一试。

.net web service: Can't add service reference, only web reference

答案 1 :(得分:0)

是的,VS2010无法从某些WSDL创建Web服务引用。必须为那些人编写自定义包装器。或者以某种方式编辑您的WSDL,以便VS可以使用它。例如,如果这些引用为您造成麻烦,可以删除您不打算使用的方法的Web服务方法引用。