2017-10-14 4 views
2

私は名前空間と契約が私によって定義されないように、特定のクライアントに対してWCFサービスを実装する必要があります。問題は、複合型をMessageBodyMemberとして使用すると、サーバー側では、指定されたメンバーがサーバー側でnullに設定されることです。ここで複雑なタイプと名前空間を持つWCF MessageBodyMember

はサンプルリクエストです:あなたが見ることができるように

<?xml version="1.0" encoding="utf-8" ?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <soapenv:Header> 
     <ns1:CustomeHeader xmlns:ns1="HEADER_NAMESPACE"> 
      <version>1.0</version> 
     </ns1:CustomeHeader> 
    </soapenv:Header> 
    <soapenv:Body> 
     <ns2:in4 xmlns:ns2="NAMESPACE_1"> 
      <ns39:userID xmlns:ns39="NAMESPACE_2"> 
       <ns40:ID xmlns:ns40="NAMESPACE_3">someFakeID_123</ns40:ID> 
       <ns41:type xmlns:ns41="NAMESPACE_3">0</ns41:type> 
      </ns39:userID> 
     </ns2:in4> 
    </soapenv:Body> 
</soapenv:Envelope> 

userIDは、そのメンバーは、名前空間を定義している複合型です。私が話しているのはMessageBodyMemberです。ここで

は、サービスおよび実装の私のインタフェース定義である:

[XmlSerializerFormat] 
public interface IIntegrationService 
{ 
    [OperationContract] 
    [XmlSerializerFormat] 
    SyncOrderRelationshipRsp syncOrderRelationship(SyncOrderRelationshipReq syncOrderRelationshipReq); 
} 

[ServiceContract] 
public class IntegrationService : IIntegrationService 
{ 
    public SyncOrderRelationshipRsp syncOrderRelationship(SyncOrderRelationshipReq syncOrderRelationshipReq) 
    { 
     //some code here ... 
    } 
} 

そしてここではSyncOrderRelationshipReqUserIDの定義です:

[MessageContract(IsWrapped = true, WrapperName = "in4", WrapperNamespace = "HEADER_NAMESPACE")] 
public class SyncOrderRelationshipReq 
{ 
    [MessageHeader(Namespace = "HEADER_NAMESPACE")] 
    public IBSoapHeader IBSoapHeader { get; set; } 

    [MessageBodyMember(Namespace = "NAMESPACE_2")] 
    public UserID userID { get; set; } 
} 

[MessageContract(WrapperNamespace = "NAMESPACE_2", IsWrapped = true)] 
public class UserID 
{ 
    [MessageBodyMember(Namespace = "NAMESPACE_3")] 
    public string ID { get; set; } 

    [MessageBodyMember(Namespace = "NAMESPACE_3", Name = "type")] 
    public int Type { get; set; } 
} 

長い話を短くするために、私はインナーが必要MessageBodyMemberのメンバーは、これらのメンバーを読むことができるように、独自の名前空間が設定されています。

答えて

1

私は最終的に答えを見つけました。答えを見つけるためにここに来た人は、これが答えです。 最初に、サービスインタフェース(これまではやっていた)にXmlSerializerFormat属性を追加する必要があります。

第2に、複合型クラスにXmlType属性を使用する必要があります。

第3に、複合型プロパティにXmlElement属性を使用します。

ので、UserIdクラスは次のようにする必要があります:

[XmlType] 
public class UserID 
{ 
    [XmlElement(Namespace = "NAMESPACE_3")] 
    public string ID { get; set; } 

    [XmlElement(Namespace = "NAMESPACE_3", Name = "type")] 
    public int Type { get; set; } 
} 

私はそれが他の人に役立ちます願っています。

関連する問題