我写了一个负责调用第三方WCF服务的类,它工作正常。我们的应用程序可以使用本地网络的代理设置进行配置,因此只需在拨打电话时使用这些设置(如果它们已设置)即可。如何使我的WCF服务调用通过已配置的本地代理服务器?
我看了一下,看不清楚如何做到这一点。我发现我使用的BasicHttpBinding对象具有ProxyAddress属性,但没有任何东西可以让我定义网络凭据或用户名和密码。
这可能就在我面前,所以我认为我只需要指出正确的方向。至少我希望这很简单!我需要做的就是告诉我的服务调用本地代理服务器以及使用什么凭证。
这是我实例化服务类的代码。我省略了构建请求类的下一部分,调用服务方法并处理结果。
// Create the service instance.
var binding = new BasicHttpBinding();
var endPoint = new EndpointAddress(new Uri(_servicesBaseUri + "MyServiceName"));
var service = new WSHsgCreateSchemeRepairClient(binding, endPoint);
// Add the MessageInspector to the contract behaviours list. This will inject the SecurityHeader XML and the SOAP action.
var soapAction = _servicesBaseUri + "MyServiceName/MyServiceMethod";
service.Endpoint.Contract.Behaviors.Add(new MessageInspector(_securityHeaderUsername, _securityHeaderPassword, soapAction));
我们有一些其他的Web服务调用(使用旧的Web服务方法)以及它们产生System.Net.WebProxy的新实例,并将其设置对服务类代理财产,但很明显,它在不同的WCF。
感谢。