2011-11-11 6 views
0

私はSoap1.1サービスに接続しています。これは、業界標準のインターフェイス定義(ユーティリティスペースでは非常に一般的なMultiSpeakという名前の)を使用している既存のサービスです。WCFクライアントのSOAPエンベロープに別のネームスペースを含める

MultiSpeak標準には、このベンダーが必要とするCustomerIDを渡すための規定は含まれていません。 SoapEvenelope少し。私の問題は、WCFが適切なXMLを発行するように説得する方法を理解できないことです。

私の現在のエンベロープは次のようになります。

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Header> 
    <h:MultiSpeakMsgHeader UserID="****" Pwd="****" Company="****" 
     xmlns="http://www.multispeak.org/Version_3.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:h="http://www.multispeak.org/Version_3.0" /> 
    </s:Header> 
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <GetAMRSupportedMeters xmlns="http://www.multispeak.org/Version_3.0" /> 
    </s:Body> 
</s:Envelope> 

ここで私はそれが仕事に見えるように必要なものです:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Header> 
    <h:MultiSpeakMsgHeader UserID="****" Pwd="****" Company="****" 
     vendor:CustomerID="StringValue" 
     xmlns="http://www.multispeak.org/Version_3.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:h="http://www.multispeak.org/Version_3.0" 
     xmlns:vendor="http://www.MyVendor.com/Multispeak3"/> 
    </s:Header> 
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <GetAMRSupportedMeters xmlns="http://www.multispeak.org/Version_3.0" /> 
    </s:Body> 

そうそこに導入された新しい名前空間です(私のベンダーのカスタム名前空間)とに既存のMultiSpeakMsgHeaderオブジェクトには、 "CustomerID"という新しいプロパティが導入されていますが、そのプロパティを表すXMLの属性は別の名前空間にあります

彼らが私に提供するWSDL(標準のMultiSPeak WSDL)はこれを生成しません。

"CustomerID"をreference.csのMultiSpeakMsgHeaderオブジェクトに文字列プロパティとして追加するのは簡単ですが、適切なxmlnsデコレーションでは出力されないため、動作しません(はい、テストしましたそれは...ネームスペースなし、愛なし)。

私は迷っています。私はWSDLを微調整して動作させることを試みたが、運がなかった。

ヒントはありますが、私は感謝しています。私はすでにこの問題に時間が掛かっています。

ありがとうございます。

答えて

1

独自の石鹸ヘッダーを作成できます。いくつかのサンプルコードは以下の通りです:

using (OperationContextScope scope = new OperationContextScope(objService.InnerChannel)) 

     { 
      UsernameToken objUsernameToken = new UsernameToken() { Username = "rajesh", Password = "rajesh" }; 
      List<Type> obj = new List<Type>(); 
      obj.Add(typeof(UsernameToken)); 

      //XmlObjectSerializer ser = new DataContractSerializer(typeof(Security), "Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", obj); 

      XmlObjectSerializer ser = new CustomXmlSerializer(typeof(Security), "Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"); 

      Security security = new Security(); 
      security.UsernameToken = objUsernameToken; 

      MessageHeader header = MessageHeader.CreateHeader("Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", 
                   security, ser, false); 

      OperationContext.Current.OutgoingMessageHeaders.Add(header); 

      try 
      { 
       //Would get a exception but the response was successful. You can see that in fiddler. 
       //The cause for the exception is that the response has the security elements mustUnderstand set to 1 chagning that to 0 would resolve the problem. Need to find on how to do that 
       string response = objService.GetInformation(); 
      } 
      catch (Exception ex) 
      { 
       OperationContext.Current.IncomingMessageHeaders.RemoveAll("Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"); 
       //throw; 
      } 

     } 

はあなたの要件に合うように上記のコードをchagneすることができます願っています。

関連する問題