【发布时间】:2017-06-02 15:26:37
【问题描述】:
我使用 HttpTransportBindingElement 和端口 80 上的 IIS 编写了一个 WCF 服务。 只要不使用代理,代码就可以正常工作。但是,如果客户有一个 http-proxy,则 WCF-Client 和 Server 之间的通信在这种情况下无法正常工作,会出现以下错误:
'没有可以接受消息的端点监听。这通常是由不正确的地址或 SOAP 操作引起的。'
只能通过代码使用设置!
这是我针对该问题的代码方法,但我坚持使用它:
bool SendClientRequest(Action<ICustomerService> channel)
{
string proxy ="my.proxy.domain:8080";
string user = "user1";
string password="secret";
// maybe i do not need this 3 lines!
WebProxy webproxy = new WebProxy(proxy, true);
webproxy.Credentials = new NetworkCredential(user, password);
WebRequest.DefaultWebProxy = webproxy;
CustomBinding customBinding = new CustomBinding();
customBinding.Elements.Add(new HttpTransportBindingElement()
{
AuthenticationSchemes.None : AuthenticationSchemes.Basic,
ProxyAddress = string.IsNullOrEmpty(proxy) ? null : new Uri(proxy),
UseDefaultWebProxy = false,
BypassProxyOnLocal = true,
TransferMode = TransferMode.Streamed,
MaxReceivedMessageSize = 84087406592,
MaxBufferPoolSize = 0x1000000,
MaxBufferSize = 0x1000000
});
using (ChannelFactory<ICustomerService> factory = new
ChannelFactory<ICustomerService>(customBinding ))
{
IClientChannel contextChannel = null;
string url = "http://my.domain.de/Distribution/eService.svc",
EndpointAddress ep = new EndpointAddress(url);
ICustomerService clientChannel = factory.CreateChannel(ep);
contextChannel = clientChannel as IClientChannel;
contextChannel.OperationTimeout = TimeSpan.FromMinutes(rcvTimeout );
channel(clientChannel); // <- here i get the exception!
return true;
}
}
我尝试了几种解决方法,但似乎没有什么比我的更具体。
【问题讨论】:
标签: c# wcf wcf-security