[英]WCF client has inconsistent behavior with multiple network interfaces
I have the WCF client shown below: 我有如下所示的WCF客户端:
public static string Execute(string a)
{
WebHttpBinding b = new WebHttpBinding();
b.Security.Mode = WebHttpSecurityMode.Transport;
WebChannelFactory<IAnimalService> f = new WebChannelFactory<IAnimalService>(b, new Uri(a));
f.Endpoint.Behaviors.Add(new WebHttpBehavior());
IWebService client = f.CreateChannel();
return client.SayHello("moo");
}
I am testing the client (in a console host) against its counterpart service from 2 different computers (A, B) and and i get different outcome. 我正在针对来自2台不同计算机(A,B)的对应服务测试客户端(在控制台主机中),并且得到了不同的结果。 Here are the similarities and differences between A and B: 以下是A和B之间的异同:
X-Squid-Error -> ERR_ACCESS_DENIED 0
). 例外情况是,在该网络接口上有一个代理,并且该代理拒绝了该请求( X-Squid-Error -> ERR_ACCESS_DENIED 0
)。 Exception: 例外:
Unhandled Exception: System.ServiceModel.Security.MessageSecurityException: The HTTP request was forbidden with client authentication scheme
'Anonymous'. ---> System.Net.WebException: The remote server returned an error: (403) Forbidden.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---
I also consulted the routing table on machine B and it shows that request should have gone on the external network interface. 我还查询了机器B上的路由表,它表明请求应该已经在外部网络接口上发出了。 I have assumed that the internal routing table would be consulted by the lower layer of the TCP-IP stack in order to forward the packet to the correct (network) medium. 我假设内部路由表将由TCP-IP堆栈的下层查询,以便将数据包转发到正确的(网络)介质。
So, I am wondering if someone would have an idea how i could get my client to pick the correct interface on machine B. I am not sure how to go about to troubleshoot the problem further. 因此,我想知道是否有人会知道如何让我的客户选择机器B上的正确接口。我不确定如何进一步解决该问题。 So any kind of advice/tips on how to get to the bottom of this situation on machine B would be most welcomed. 因此,关于如何在机器B上解决这种问题的任何建议/提示都将受到欢迎。
Try to use this snippet in you config file, so you will be able to use your default credentials to autenticate in the proxy server. 尝试在配置文件中使用此代码段,以便您将能够使用默认凭据在代理服务器中自动启动。
<system.net>
<defaultProxy useDefaultCredentials="true" />
</system.net>
似乎默认情况下,绑定试图在计算机B上寻找默认的代理设置。添加以下绑定配置解决了该问题:
b.UseDefaultWebProxy = false;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.