3

「エコー」リクエストをサードパーティのJavaベースのプロデューサーに送信する単純なwcfコンシューマークライアントがあります。WS-Security を正しく機能させるのにしばらく苦労しましたが、今では要求を送信し、応答を受け取ることができます。返信がクライアントに届いたときのみ、値は null です。

IClientMessageInspector を使用して正しい応答があることを確認しましたが、サービスへの呼び出しは常に null を返します。

これが私のクライアント コードです。(「MyEndPointBehavior」への呼び出しは、メッセージ インスペクタを追加するだけです)

string echoString = EchoTesttextbox.Text;

string url = "https://somewhere.com/uk-producer/UKService";

// create the endpoint address
EndpointAddress endPointAddress = new EndpointAddress(new Uri(url), EndpointIdentity.CreateDnsIdentity("TestProducer"));

PortBindingClient client = new PortBindingClient("Port12", endPointAddress);
client.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.Root, X509FindType.FindByThumbprint, ".....");
client.ClientCredentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.LocalMachine, StoreName.TrustedPeople, X509FindType.FindByThumbprint, ".....");
client.Endpoint.Behaviors.Add(new MyEndpointBehavior());

string response = String.Empty;
response = client.echo(echoString);

MessageBox.Show(response);

そして私のメッセージインペクターコード;

public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
     // Implement this method to inspect/modify messages after a message
     // is received but prior to passing it back to the client

     // make a copy of the reply that we can play with
     MessageBuffer buffer = reply.CreateBufferedCopy(Int32.MaxValue);
     // the message variable holds a reference to a copy of the initial reply
     Message message = buffer.CreateMessage();

     // assign a copy back to the ref received so it can continue undisturbed
     reply = buffer.CreateMessage();

     StringWriter stringWriter = new StringWriter();
     XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
     message.WriteBody(xmlTextWriter);
     xmlTextWriter.Flush();
     xmlTextWriter.Close();

     string body = stringWriter.ToString();

}

私の質問は、IClientMessageInspector.AfterReceiveReply と MessageBox に応答を表示しようとする間で何が起こっているのですか? 何が起こっているのかを理解しようとすることができれば、応答が通過しない理由を突き止められるかもしれません。

4

4 に答える 4

3

それはとてもイライラしました。null 値を受け取った理由は、すべて名前空間に関係していました。

IClientMessageInspector 内で SOAP 本体を調べて、これを確認できました

<soapenv:Body wsu:Id="Id-1555290177" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<me:EchoResponse xmlns:me="http://somewhere.com/uk-producer/UKService">test11</me:EchoResponse>
</soapenv:Body>

WSDL と reference.cs (サードパーティの WSDL から VS2012 の「サービス参照の追加」機能を使用してプロキシを生成しました) はこれを示しています。

[System.ServiceModel.MessageBodyMemberAttribute(Name="EchoResponse", Namespace="http://somewhere.com/uk-producer/UKService/", Order=0)]
public string EchoResponse1;

そして、長い間、すべて問題ないように見えました。しかし、その後、欲求不満から、reference.csをこれに変更してみました

[System.ServiceModel.MessageBodyMemberAttribute(Name="EchoResponse", Namespace="http://somewhere.com/uk-producer/UKService", Order=0)]
public string EchoResponse1;

名前空間の最後のスラッシュのみを削除しました

そして、それはすべてうまくいきました。

于 2013-09-10T12:09:26.690 に答える