如何配置svcutil生成的代码以便重新生成正确的WSDL?

时间:2010-11-29 17:31:53

标签: .net wsdl svcutil.exe

我正在尝试从现有的WSDL生成.NET SOAP Web服务(使用svcutil)。 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>

生成的代码编译和部署正常,但 it 生成的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?

1 个答案:

答案 0 :(得分:0)

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