我有一个简单的 wcf 消费者客户端,它将“echo”请求发送到基于 Java 的第 3 方生产者。我一直在努力让 WS-Security 正常运行,但现在可以发送请求和接收回复。只有当回复到达我的客户时,该值为空。
我已经使用 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 中显示响应之间发生了什么?如果我可以尝试了解正在发生的事情,我也许可以尝试找出响应没有通过的原因。