【发布时间】:2010-11-19 11:22:15
【问题描述】:
我编写了一个负责调用第三方 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 实例并将其设置为服务类 Proxy 属性,但显然它在 WCF 中有所不同。
谢谢。
【问题讨论】: