1

我想允许我的一些 SOAP 标头元素是可空的。这对于正文元素是可能的,但我不确定标题元素是否允许这样做。

在下面的示例消息中,我想允许 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>
4

1 回答 1

1

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

    [System.ServiceModel.MessageHeaderAttribute(Namespace="...")]
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
    public System.Nullable<System.DateTime> MessageDateTime;
于 2012-10-09T22:17:53.397 回答