代码之家  ›  专栏  ›  技术社区  ›  Matthew Murdoch

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

  •  1
  • Matthew Murdoch  · 技术社区  · 15 年前

    svcutil )从现有的WSDL。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,但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 回复  |  直到 15 年前
        1
  •  0
  •   Community Mohan Dere    9 年前

    根据对 similar question ReplyAction = "*" 分开,但保留 OperationContract 属性

    推荐文章