我使用HttpTransportBindingElement與端口80上的IIS一起編碼了一個WCF服務。 只要沒有使用代理,代碼就可以正常工作。但是,如果客戶有一個http代理,WCF客戶端和服務器之間的通信在這種情況下通過發生以下錯誤不起作用:如何在WCF上使用HttpTransportBindingElement設置代理憑證?
'沒有端點正在聽......以接受該消息。這通常是由不正確的地址或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;
}
}
我嘗試了幾種解決方案,但似乎沒有什麼具體像我一樣。