当用户在代理后面时从客户端应用程序访问 WCF 服务 [英] WCF service access from client application when user is behind proxy

查看:45
本文介绍了当用户在代理后面时从客户端应用程序访问 WCF 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器上托管了一个 WCF 服务.客户端应用程序正在访问 Windows 7 计算机上的服务.Windows 7 机器上有两个用户.Windows 应用程序是通过 Clickonce 安装的,因此两个用户将有单独的实例.

I have a WCF service hosted on a server. A client application is accessing the service on a windows 7 machine. There are two users on Windows 7 machine. Windows application is a installed through Clickonce so separate instance will be there for two users.

当用户 A 通过 Winforms 应用程序访问服务时它工作正常,但是当同一台机器上的用户 B 尝试访问它时会引发以下异常:通信异常:远程服务器返回意外响应:(417) 期望失败.

When userA accessing the service through Winforms application it works fine, but when userB on the same machine trying to access it throws following exception: Communication Exception: The remote server returned an unexpected response: (417) Expectation failed.

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Myapp.ServiceProxy.IMyAPIService.GetData(String userName, String passWord)

为一个用户工作而不为其他用户工作的原因是什么?我错过了什么吗?

更新:虽然我找到了这个问题的解决方案(请参阅下面的答案),但仍然想知道在这种情况下应该做什么.正如 MSDN 文章所说,它阻止用户发送大量数据到服务器,但它没有提到任何限制?

UPDATE: Though I found a solution (Please see my answer below) to this issue but still wanted to know what should be done in this scenario. As MSDN article says it blocks user to send large amount of data to server, but it didn't mention about any limit in that?

客户端可以发送到服务器的数据限制是多少?有没有更好的方法可以从代理后面的客户端连接 WCF 服务?

What is the limit of data client can send to server? Is there any better approach for connecting a WCF service from a client who is behind proxy?

推荐答案

我终于破解了.发生这种情况是因为用户在代理后面.

Finally I cracked it. It happens because the user is behind a proxy.

app.config 中的以下设置解决了问题:

Following setting in the app.config resolved the issue:

<system.net>
   <settings>
      <servicePointManager expect100Continue="false" />
   </settings>
</system.net>

但是对于大文件上传来说这仍然是一个问题,现在正在寻找相同的解决方案.

But this is still an issue for large file upload, looking for a solution for the same now.

MSDN 文章

这篇关于当用户在代理后面时从客户端应用程序访问 WCF 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆