繁体   English   中英

C#SOAP服务-删除方法节点并在soapheader节点中具有标头

[英]C# SOAP Service - Remove method node and have header in soapheader node

我的任务是创建一个符合特定wsdl的Web服务,并且以前没有使用过SOAP或asmx。

当我在SoapUI中创建请求时,我得到以下结构,该结构与客户端将用于发送请求的结构相同。 (使用占位符名称)

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:par="http://www.foo.com/schemas/method">
   <soapenv:Header>
      <par:SOAPHeaderRequest>
         <par:ApplicationID>ID</par:ApplicationID>
      </par:SOAPHeaderRequest>
   </soapenv:Header>
   <soapenv:Body>
      <par:Body>
      </par:Body>
   </soapenv:Body>
</soapenv:Envelope>

但是,当我尝试创建服务时,我具有以下结构:

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Method xmlns="http://www.foo.com/schemas/method">
      <request>
        <SOAPHeaderRequest>
          <ApplicationID>string</ApplicationID>
        </SOAPHeaderRequest>
        <body>
          <Property>string</Property>
        </body>
      </request>
    </Method>
  </soap:Body>
</soap:Envelope>

我想知道如何删除Method节点包装,以及如何将SOAPHeaderREquest移动到soap:Header中。

这是我的示例代码:

界面和对象

 [ServiceContract(Namespace = "http://www.foo.com/schemas/method")]
 public interface IServiceContract
 {
     [XmlSerializerFormat]
     [OperationContract]
     ResponseObject Method(RequestObject request);
 }

 [System.Serializable()]
 [System.Xml.Serialization.XmlType(AnonymousType = true, Namespace = "http://www.foo.com/schemas/method")]
 [MessageContract(IsWrapped = false)]
 public class RequestObject
 {
     [System.ServiceModel.MessageHeader(Namespace = "http://www.foo.com/schemas/method")]
     public SOAPHeaderRequest SOAPHeaderRequest;

     [System.ServiceModel.MessageBodyMember(Namespace = "http://www.foo.com/schemas/method", Order = 0)]
     public Body body;

     public RequestObject()
     {
     }

     public RequestObject(SOAPHeaderRequest SOAPHeaderRequest, Body body)
     {
         this.body = body;
     }
 }

 [System.Serializable()]
 [System.Xml.Serialization.XmlType(AnonymousType = true, Namespace = "http://www.foo.com/schemas/method")]
 [MessageContract(IsWrapped = false)]
 public class ResponseObject
 {
     [System.ServiceModel.MessageHeader(Namespace = "http://www.foo.com/schemas/method")]
     public SOAPHeaderResponse SOAPHeaderResponse;

     [System.ServiceModel.MessageBodyMember(Namespace = "http://www.foo.com/schemas/method", Order = 0)]
     public Body body;
 }


 [System.Serializable()]
 public class Body
 {
     public string Property { get; set; }
 }

ASMX

[WebService(Namespace = "http://www.foo.com/schemas/method")]
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
public class M5NapaPartUpdateService : WebService, IServiceContract
{
    [WebMethod]
    [SoapMethod(SoapAction = "method")]
    public ResponseObject Method(RequestObject request)
    {
        return new ResponseObject();
    }
}

让我知道您是否还有其他需要。

谢谢!

WSDL区分两种消息样式:document和RPC。

消息样式影响SOAP主体的内容: 文档样式: SOAP主体包含一个或多个称为part的子元素。 主体所包含的内容没有SOAP格式化规则。 它包含发送方和接收方所同意的内容。

** RPC样式:** RPC表示SOAP正文包含一个元素,该元素具有被调用的方法或操作的名称。 该元素又包含该方法/操作的每个参数的元素。

您的wsdl以Document Literal样式编写。

如果您使用服务合同,那么我相信您正在使用WCF框架编写服务代码。

您可以指定以下参数来按预期制作WSDL。

 [ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples"), XmlSerializerFormat(Style = OperationFormatStyle.Document, 
                             Use = OperationFormatUse.Literal)]

参考-https://www.ibm.com/support/knowledgecenter/en/SSB27H_6.2.0/fa2ws_ovw_soap_syntax_lit.html

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM