2012-10-05 96 views
1

我想允許我的一些SOAP標頭元素是可填充的。這對body元素是可能的,但我不確定它是否允許來自標題元素。Nillable 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> 

回答

1

只要定義允許,它是允許的。就你而言,你所要做的就是將nillable="true"添加到元素的定義中。 .NET w/WCF上的結果看起來像這樣:

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