ame*_*exn 6 .net c# windows wcf
我们的团队尝试使用Internet代理服务器创建一个Windows应用程序(c#)来调用WCF服务
在调用WCF服务时显示异常"服务器提交了协议违规.Section = ResponseStatusLine"
请给出建议来解决这个问题/任何其他替代解决方案
//Code for creating proxy
public static DevicesServiceClient CreateProxy()
{
var proxy = new DevicesServiceClient("BasicHttpBinding_IDevicesService");
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.None;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
binding.UseDefaultWebProxy = false;
binding.ProxyAddress = new Uri(string.Format("http://{0}:{1}", "192.168.0.20","808"));
proxy.Endpoint.Binding = binding;
proxy.ClientCredentials.UserName.UserName = "Username";
proxy.ClientCredentials.UserName.Password = "Password";
}
Run Code Online (Sandbox Code Playgroud)
服务器堆栈跟踪:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException,HttpWebRequest request,HttpAbortReason abortReason)
at ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message,时间跨度超时)
在System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,时间跨度超时)
在System.ServiceModel.Channels.ServiceChannel.Call(字符串动作,布尔单向,ProxyOperationRuntime操作,对象[]项,对象[]奏, TimeSpan超时)
在System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime操作,Object [] ins,Object []出)
在System的System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)
中. ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息)在[0]
处重新抛出异常:位于DevicesService.IDevicesService
处System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&msgData,Int32类型)的System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)
. CheckNetworkConnection(String ipAddress)
我在app.config中的客户端代码

我在web.config中的服务器端代码

使用代理服务器从 Windows 客户端应用程序调用 wcf 服务的代码
{
var proxy = new DevicesServiceClient("BasicHttpBinding_IDevicesService");
BasicHttpBinding binding = new BasicHttpBinding("BasicHttpBinding_IDevicesService");
var proxySettings = ApplicationDetails.CheckProxySettings();
Uri domainAddress;
var strtemp = new string[] { };
//WebProxy webproxy = new WebProxy();
var networkCredentials = new NetworkCredential();
if (proxySettings.ProxyServerType == "http")
{
domainAddress = new Uri(string.Format("http://{0}:{1}", proxySettings.ProxyServerAddress, proxySettings.ProxyServerPort));
}
else if (proxySettings.ProxyServerType == "https")
{
domainAddress = new Uri(string.Format("https://{0}:{1}", proxySettings.ProxyServerAddress, proxySettings.ProxyServerPort));
}
else
{
domainAddress = new Uri(string.Format("http://{0}:{1}", proxySettings.ProxyServerAddress, proxySettings.ProxyServerPort));
}
//
WebProxy webproxy = new WebProxy(domainAddress.ToString(), true, strtemp);
//
//networkCredentials.Domain = domainAddress.ToString();
if (proxySettings.ProxyAuthentication == "1")
{
networkCredentials.UserName = proxySettings.Username;
networkCredentials.Password = proxySettings.Password;
}
webproxy.Credentials = networkCredentials;
webproxy.BypassProxyOnLocal = false;
WebRequest.DefaultWebProxy = webproxy;
binding.UseDefaultWebProxy = true;
proxy.Endpoint.Binding = binding;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6503 次 |
| 最近记录: |