Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF service access from client application when user is behind proxy

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.

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)

What could be the reason behind working for one user and not for other? Am I missing anything?

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?

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?

like image 655
JPReddy Avatar asked Feb 17 '11 19:02

JPReddy


People also ask

How will you specify a method is available to access by client in WCF?

With the service running, right click the project that will contain the WCF client proxy and select Add > Service Reference. In the Add Service Reference Dialog, type in the URL to the service you want to call and click the Go button. The dialog will display a list of services available at the address you specify.

How do I add a WCF service reference to the console application?

In the Solution Explorer, right click on the References folder and click on Add Service Reference. The Add Service Reference wizard will pop up. In the Address section, enter the WCF service URL and then click on Go button.

What is client proxy in WCF?

Proxy is an object in memory on the client-side that exposes the same Interface or API that the WCF service does. Your consuming code will make calls against that proxy and proxy will dispatch those calls as SOAP Messages to the WCF service.

What is the use of proxy class in WCF?

Actually Proxy is a class in WCF that is used to communicate with client application. We can simply get the entire configuration through the proxy class. There is no need to do extra effort to generate the configuration setting for the client. Proxy class used when you think that your service must be loosely coupled.


1 Answers

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

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.

More information on this in MSDN article

like image 86
JPReddy Avatar answered Sep 24 '22 17:09

JPReddy