0

I have a winForms application running on a server and I access it from another application via a Service which is running over a ServiceHost.

The problem is, when the data which the client wants to get from the ServiceHost is to big I get a exception like:

Error while receiving, the reason could be not using a http-protocol.

How can I solve this? Would this be a web application I simply would increase the maxRequestLength/executionTimeout in the web.config. but there is no web.config in a winforms project.

EDIT: here is some code:

Service s = new Service(this.foo);
ServiceHost host = new ServiceHost(s, baseAddress);
host.AddServiceEndpoint(typeof(IService), new BasicHttpBinding(), "");
host.Open();
Eva Dias
  • 1,709
  • 9
  • 36
  • 67
gurehbgui
  • 14,236
  • 32
  • 106
  • 178
  • You didn't quote the exception message accurately. Document your question better by also enabling logging: http://msdn.microsoft.com/en-us/library/ms730064.aspx – Hans Passant Oct 25 '12 at 10:20

1 Answers1

0

When creating the binding (in your example BasicHttpBinding) just set its MaxReceivedMessageSize (http://msdn.microsoft.com/de-de/library/system.servicemodel.httpbindingbase.maxreceivedmessagesize.aspx) to the value appropriate for your scenario.

    var binding = new BasicHttpBinding { MaxReceivedMessageSize = 20000; };
Daniel
  • 64
  • 1
  • I just noticed, that I havn't read the exception message you provided. It states that you were possibly not using a HTTP protocol while specifying a HTTP Binding. What is the address of the service? – Daniel Oct 25 '12 at 08:16
  • its a http adress. and its working for a limit of <3000 elements. when i get more, i get the exception – gurehbgui Oct 25 '12 at 08:29
  • The problem is that your exception is just a genaral one. So it's hard to say what exactly causes the error. As far as I understood your scenario, you have a WCF service hosted inside a Windows Forms app and a client application accessing the service. Make sure you use the same binding configuration on both sides (especially with the MaxReceivedMessageSize property). You may also add a system.servicemodel section to your app.config and add configuration data for your service there. Afterwards it'll be easier to use the same configuration on the client. – Daniel Oct 25 '12 at 08:48