2010-11-29 95 views
1

我正嘗試從現有的WSDL生成.NET SOAP Web服務(使用svcutil)。該WSDL包含以下信息:如何配置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> 

生成的代碼編譯和部署OK但產生不包含DoStuff操作細節的WSDL。

如果我刪除[OperationContract(ReplyAction = "*")]屬性,那麼我從服務中獲得以下錯誤:

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. 

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")]屬性

此外,從請求代碼中刪除[MessageContract(IsWrapped="false")]屬性會使所有錯誤消失,但(可能並不意外)會導致請求需要用元素打包。

我需要對生成的代碼做些什麼才能重新生成正確的WSDL?

+0

仔細看看你的名字空間。看起來你正在引用錯誤的命名空間。 – 2010-11-29 21:11:29

回答