Xsd 零SOAP头

Xsd 零SOAP头,xsd,wsdl,Xsd,Wsdl,我希望允许我的一些SOAP头元素为nillable。这对于body元素是可能的,但我不确定是否允许从header元素使用它 在下面的示例消息中,我希望允许MessageDateTime为null <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap=

我希望允许我的一些SOAP头元素为nillable。这对于body元素是可能的,但我不确定是否允许从header元素使用它

在下面的示例消息中,我希望允许MessageDateTime为null

<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>

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

    [System.ServiceModel.MessageHeaderAttribute(Namespace="...")]
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
    public System.Nullable<System.DateTime> MessageDateTime;
[System.ServiceModel.MessageHeaderAttribute(命名空间=“…”)]
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
公共系统。可为空的MessageDateTime;

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

    [System.ServiceModel.MessageHeaderAttribute(Namespace="...")]
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
    public System.Nullable<System.DateTime> MessageDateTime;
[System.ServiceModel.MessageHeaderAttribute(命名空间=“…”)]
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
公共系统。可为空的MessageDateTime;