「エコー」リクエストをサードパーティの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 に応答を表示しようとする間で何が起こっているのですか? 何が起こっているのかを理解しようとすることができれば、応答が通過しない理由を突き止められるかもしれません。