1

我正在尝试svcutil从现有的 WSDL 生成 .NET SOAP Web 服务(使用 )。WSDL 包含以下信息:

<types>
<xsd:schema>
<!-- ... -->
<xsd:complexType name="DoStuffType">
  <xsd:sequence>
    <xsd:element name="..." type="..." />
  </xsd:sequence>
</xsd:complexType>
<xsd:complexType name="DoStuffResponseType">
  <xsd:sequence>
    <xsd:element name="..." type="..." />
  </xsd:sequence>
</xsd:complexType>
<xsd:element name="DoStuff" type="tns:DoStuffType" />
<xsd:element name="DoStuffResponse" type="tns:DoStuffResponseType" />
</xsd:schema>
</types>

<message name="DoStuffSoapIn">
  <part name="messagePart" element="tns:DoStuff" />
</message>
<message name="DoStuffSoapOut">
  <part name="messagePart" element="tns:DoStuffResponse" />
</message>

<portType name="ASoapService">
  <operation name="DoStuff">
    <input message="tns:DoStuffSoapIn" />
    <output message="tns:DoStuffSoapOut" />
  </operation>
</portType>

生成的代码可以编译和部署,但生成的 WSDL 不包含DoStuff操作的详细信息。

如果我删除该[OperationContract(ReplyAction = "*")]属性,那么我会从服务中收到以下错误:

System.InvalidOperationException: An exception was thrown in a call to a 
  WSDL export extension: 
System.ServiceModel.Description.DataContractSerializerOperationBehavior 
  contract: http://example.com/services:ASoapService----> 
System.InvalidOperationException: Top level XML element with name
  DoStuffResponse in namespace http://example.com/services cannot reference
  http://schemas.datacontract.org/2004/07/Generated:DoStuffResponseType type 
  because it already references a different type 
  (http://example.com/services:DoStuffResponseType). 
Use a different operation name or MessageBodyMemberAttribute to specify a 
  different name for the Message or Message parts.

如果我[MessageContract(IsWrapped="false")]从响应代码中删除该属性,则会收到以下错误:

System.InvalidOperationException: The operation 'DoStuff' could not be loaded 
  because it has a parameter or return type of type 
  System.ServiceModel.Channels.Message or a type that has 
  MessageContractAttribute and other parameters of different types. When using 
  System.ServiceModel.Channels.Message or types with MessageContractAttribute, 
  the method must not use any other types of parameters.

此外,[MessageContract(IsWrapped="false")]从请求代码中删除属性会使所有错误消失,但(可能并不奇怪)会导致请求需要用<request>元素包装。

我需要对生成的代码做些什么来让它重新生成正确的 WSDL?

4

1 回答 1

0

根据类似问题的答案,解决方案是删除ReplyAction = "*"部分,但保留OperationContract属性。

于 2013-05-13T14:07:57.227 回答