Nillable SOAP标头

时间:2012-10-05 10:59:44

标签: xsd wsdl

我想允许我的一些SOAP标头元素为空。这对于body元素是可行的,但我不确定它是否允许来自header元素。

在下面的示例消息中,我想允许MessageDateTime为空。

<definitions  xmlns="http://schemas.xmlsoap.org/wsdl/"
              xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
              xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
              xmlns:tns="http://mycompany.com/repositoryservice">
  <types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema"
            attributeFormDefault="qualified"
            elementFormDefault="qualified"
            targetNamespace="http://mycompany.com/repositoryservice">
      <element name="MessageDateTime" type="dateTime" />
      <element name="SaveRequest">
        <!-- complexType -->
      </element>
    </schema>
  </types>
  <message name="SaveRequest_Headers">
    <part name="MessageDateTime" element="tns:MessageDateTime" />
  </message>
  <message name="SaveRequest">
    <part name="parameters" element="tns:SaveRequest" />
  </message>
  <binding name="RepositoryServiceBinding" type="tns:IRepositoryService">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <operation name="Save">
      <soap:operation soapAction="http://mycompany.com/repositoryservice/Save" style="document" />
      <input name="SaveRequest">
        <soap:header message="tns:SaveRequest_Headers" part="MessageDateTime" use="literal" />
        <soap:body use="literal" />
      </input>
    </operation>
  </binding>
  <!-- service, portType -->
</definitions>

1 个答案:

答案 0 :(得分:1)

只要定义允许,它就被允许。在您的情况下,您所要做的就是将nillable="true"添加到元素的定义中。 .NET w / WCF的结果如下所示:

    [System.ServiceModel.MessageHeaderAttribute(Namespace="...")]
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
    public System.Nullable<System.DateTime> MessageDateTime;