Rectangle 27 150

In your binding configuration, there are four timeout values you can tweak:

<bindings>
  <basicHttpBinding>
    <binding name="IncreasedTimeout"
             sendTimeout="00:25:00">
    </binding>
  </basicHttpBinding>

The most important is the sendTimeout, which says how long the client will wait for a response from your WCF service. You can specify hours:minutes:seconds in your settings - in my sample, I set the timeout to 25 minutes.

The openTimeout as the name implies is the amount of time you're willing to wait when you open the connection to your WCF service. Similarly, the closeTimeout is the amount of time when you close the connection (dispose the client proxy) that you'll wait before an exception is thrown.

The receiveTimeout is a bit like a mirror for the sendTimeout - while the send timeout is the amount of time you'll wait for a response from the server, the receiveTimeout is the amount of time you'll give you client to receive and process the response from the server.

In case you're send back and forth "normal" messages, both can be pretty short - especially the receiveTimeout, since receiving a SOAP message, decrypting, checking and deserializing it should take almost no time. The story is different with streaming - in that case, you might need more time on the client to actually complete the "download" of the stream you get back from the server.

There's also openTimeout, receiveTimeout, and closeTimeout. The MSDN docs on binding gives you more information on what these are for.

To get a serious grip on all the intricasies of WCF, I would strongly recommend you purchase the "Learning WCF" book by Michele Leroux Bustamante:

and you also spend some time watching her 15-part "WCF Top to Bottom" screencast series - highly recommended!

I've tried to add the binding sections to <system.serviceModel> in web.config, but its throwing an error now.... any additional steps I've missed out on...

I also changed the endpoint in my service to the <endpoint address="" binding="IncreasedTimeout" - is this the wrong thing to do?

exactly - the binding is the type of protocol you use - basicHttp, wsHttp, netTcp. The binding configuration is this configuration you create in config to modify timeouts etc.

Funny even after doing this, still getting a timeout error, Marc can you please give as much information as possible?

WCF Service , how to increase the timeout? - Stack Overflow

wcf
Rectangle 27 140

A service application includes a website host already setup for you. A service library is a library of services that a host can reference and startup.

If you start with a service library (recommended) you can then choose any host you wish (a windows service, IIS/ASP.NET, or even a console application) and you'd just reference your library from your new host. Choosing a Service Application limits your host to just IIS/ASP.NET (though this might be ok for your purposes, but will limit the protocols you can use).

Edit: Changes in IIS since I wrote this allow for a wider variety of protocols on ASP.NET activated services, so choosing a service application is much less limiting than before.

Anyone have info about the new protocols / bindings available when hosting on IIS?

@AndersonImes I know this is an old post, but hoping you can help. I've been looking everywhere and can't find whether or not WCF Service is intended to replace Web Service in .NET 3.5 and thus why the template was removed in .NET 4? Thanks. :)

@Chiramisu WCF provides many more advantages and flexibility ... I found these very helpful: Codeproject example , Stackoverflow question

@Sam Thanks Sam, very helpful. So basically WCF can do everything a Web Service can and more? Any limitations I wonder... :)

@Chiramisu glad to help! There's always limitations, but WCF has far less limitations than a typical web service, I'd imagine.

wcf binding - What is the difference between a WCF Service Application...

wcf wcf-binding wcf-security
Rectangle 27 9

You basically need 2 endpoints for the same service exposed at different addresses and aligned with different bindings. This may help you.

Thanks for the clarification. The link was exactly describes exactly what I was looking for.

.net - WCF: Multiple binding configurations for a single service - Sta...

.net wcf wcf-binding
Rectangle 27 61

Removing the name from your binding will make it apply to all endpoints, and should produce the desired results. As so:

<services>
  <service name="Service.IService">
    <clear />
    <endpoint binding="basicHttpBinding" contract="Service.IService" />
  </service>
</services>
<bindings>
  <basicHttpBinding>
    <binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
        maxArrayLength="16348" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    </binding>
  </basicHttpBinding>
  <webHttpBinding>
    <binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
  </webHttpBinding>
</bindings>

Also note that I removed the bindingConfiguration attribute from the endpoint node. Otherwise you would get an exception.

Thank you very much. As a note I also had to remove the bindingConfiguration attribute from my endpoint since it referenced a name I took out.

What else do I need to do in addition to above changes in web.config?

c# - WCF service maxReceivedMessageSize basicHttpBinding issue - Stack...

c# wcf wcf-binding
Rectangle 27 2

Just as an update.

I changed the service binding from basicHttpBinding to wsHttpBinding. Changing the binding to wsHttpBinding changed the SOAP service to send as a SOAP 1.2 call rather than a SOAP 1.1 call. Once I did this, the content types matched on the send and receive calls which resolved the binding mismatch error.

WCF service binding content type mismatch - text/xml and application/s...

wcf-binding content-type
Rectangle 27 10

If all you have is the one project I see only added complexity if you separate for the heck of it. I used a library when I had some particular use cases where I had to host in both a windows service and in IIS.

For IIS you you can move the classes and interfaces to a library but keep your .SVC files in the web project. You must edit the .SVC files to point to the properly qualified classes.

wcf binding - What is the difference between a WCF Service Application...

wcf wcf-binding wcf-security
Rectangle 27 107

<binding name="MyService.MyServiceBinding" 
           maxReceivedMessageSize="4194304">

The main reason the default (65535 I believe) is so low is to reduce the risk of Denial of Service (DoS) attacks. You need to set it bigger than the maximum request size on the server, and the maximum response size on the client. If you're in an Intranet environment, the risk of DoS attacks is probably low, so it's probably safe to use a value much higher than you expect to need.

By the way a couple of tips for troubleshooting problems connecting to WCF services:

I tried to do the same at my end, but could not taste success.

Useful blog post: geekswithblogs.net/smyers/archive/2011/10/05/ - I just want to point out to people reading this answer that the above code snippet in the answer should go into the bindings section of your binding. Ex: Let's let the binding be basicHttpBinding: <bindings><basicHttpBinding><binding ... /><readerQuotas ... /></basicHttpBinding></bindings> - also the <readerQuotas maxArrayLength="" /> may have to be set (I had to).

c# - Large WCF web service request failing with (400) HTTP Bad Request...

c# .net wcf web-services
Rectangle 27 107

<binding name="MyService.MyServiceBinding" 
           maxReceivedMessageSize="4194304">

The main reason the default (65535 I believe) is so low is to reduce the risk of Denial of Service (DoS) attacks. You need to set it bigger than the maximum request size on the server, and the maximum response size on the client. If you're in an Intranet environment, the risk of DoS attacks is probably low, so it's probably safe to use a value much higher than you expect to need.

By the way a couple of tips for troubleshooting problems connecting to WCF services:

I tried to do the same at my end, but could not taste success.

Useful blog post: geekswithblogs.net/smyers/archive/2011/10/05/ - I just want to point out to people reading this answer that the above code snippet in the answer should go into the bindings section of your binding. Ex: Let's let the binding be basicHttpBinding: <bindings><basicHttpBinding><binding ... /><readerQuotas ... /></basicHttpBinding></bindings> - also the <readerQuotas maxArrayLength="" /> may have to be set (I had to).

c# - Large WCF web service request failing with (400) HTTP Bad Request...

c# .net wcf web-services
Rectangle 27 6

Yes it is possible. JSON and SOAP need different bindings so your service needs two endpoints - one with webHttpBinding and webHttp endpoint behavior and second with basicHttpBinding or other SOAP oriented binding. These endpoints must have different relative addresses.

If you want to support both JSON and XML (POX not SOAP) formats in REST service you can do it on the same endpoint in WCF 4 by defining automaticFormatSelectionEnabled="true" in the webHttp behavior used for the REST endpoint. This allows the endpoint to return the data formatted either as JSON or as XML. The choice of the format is based on the format of incoming request so a request in JSON will get a response in JSON and a request in XML will get a response in XML.

Thanks! But since I have a soap service already running, I would like the format to be switched between SOAP and JSON. Is that possible? Will try out.

No it is not possible because SOAP and JSON needs different endpoints.

WCF service method to return json or soap - Stack Overflow

wcf json rest service
Rectangle 27 6

Yes it is possible. JSON and SOAP need different bindings so your service needs two endpoints - one with webHttpBinding and webHttp endpoint behavior and second with basicHttpBinding or other SOAP oriented binding. These endpoints must have different relative addresses.

If you want to support both JSON and XML (POX not SOAP) formats in REST service you can do it on the same endpoint in WCF 4 by defining automaticFormatSelectionEnabled="true" in the webHttp behavior used for the REST endpoint. This allows the endpoint to return the data formatted either as JSON or as XML. The choice of the format is based on the format of incoming request so a request in JSON will get a response in JSON and a request in XML will get a response in XML.

Thanks! But since I have a soap service already running, I would like the format to be switched between SOAP and JSON. Is that possible? Will try out.

No it is not possible because SOAP and JSON needs different endpoints.

WCF service method to return json or soap - Stack Overflow

wcf json rest service
Rectangle 27 9

You need to know three things to call a WCF service:

net.tcp://localhost:25488/MyDataAccessService/MyFirstBindingAddress
netTcpBinding
  • Contract - the service contract (the public interface IMyDataAccessService) to define the service methods and parameters needed

Once you have these things, you can easily set up a client in code:

NetTcpBinding binding = new NetTcpBinding(NetTcpBinding.None);
EndpointAddress address = new EndpointAddress("net.tcp://localhost:25488/MyDataAccessService/MyFirstBindingAddress");

ChannelFactory<IMyDataAccessService> channelFactory = new ChannelFactory<IMyDataAccessService>(binding, address);
IMyDataAccessService _clientProxy = channelFactory.CreateChannel();

and now your _clientProxy can easily call up the methods on the server, passing in the parameters etc.

Of course, for this to work, you must have the contract! E.g. you must have access to the file that define the service contract (and possibly the data contracts, too - the data types being sent back and forth). Since you're using the netTcpBinding, I'm assuming both ends of the wire are built using .NET here.

Those items can easily be included into a separate class library project that both the service developers as well as the client-side developers can share and use.

What if I need to call a remote service...where the address is something like this... {net.tcp://RemoteServer:25488/MyDataAccessService/MyFirstBindingAddress} Is there any security settings needed ? I am getting an error as "The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state. System.Exception {System.ServiceModel.CommunicationObjectFaultedException

@marc_s Is it possible to exchange the contract info automatically? Just like clicking "Add Service Reference" and let Visual Studio automatically generate the proxies?

nettcpbinding - How to consume WCF Service with net tcp binding and wi...

wcf nettcpbinding
Rectangle 27 3

For secured communication channels, use the mexHttpsBinding (with the additional s) instead of the mexHttpBinding, see: http://msdn.microsoft.com/en-us/library/aa967391.aspx and also replace

<serviceMetadata httpGetEnabled="true" />
<serviceMetadata httpsGetEnabled="true" />

also with the additional s.

wcf binding - Adding WCF serivce reference, or using svcutil.exe for m...

wcf wcf-binding wcf-security wcf-client
Rectangle 27 2

Seems like your doing a few steps too many - too complicated. Why don't you just use a binding configuration based on an existing binding?? Something like this:

<bindings>
  <basicHttpBinding>
    <binding name="largeBinding"
          maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas
          maxArrayLength="2147483647" maxBytesPerRead="2147483647"
          maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" />
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service name="MyService" behaviorConfiguration="MyServiceBehavior" >
    <endpoint 
        address="" 
        binding="basicHttpBinding" 
        bindingConfiguration="largeBinding"
        contract="MyContract" />
    <endpoint 
        address="mex" 
        binding="mexHttpBinding" 
        contract="IMetadataExchange" />
  </service>
</services>

Define the exact same binding configuration on the client side and use it there, too.

Also, your MEX endpoint for metadata exchange should NEVER have any special setup - just use the default mexHttpBinding and don't configure any binding configuration for that.

In fact you don;t need a mex endpoint at all if you are happy to serve the metadata as WSDL - just set the httpGetEnabled = true (and possibly httpGetUrl if you don;t have a base address) on the serviceMetadata behavior

wcf binding - Transferring big amount of data (more than 64kb) through...

wcf wcf-binding
Rectangle 27 35

This is simply happening because you have configured a single endpointBehavior for both the SOAP and REST endpoints but the SOAP endpoint can't have the webHttp behavior. You need to split these apart so that they are:

<endpointBehaviors>
    <behavior name="SOAPDemoEndpointBehavior">
      <ipFilter/>
    </behavior>
    <behavior name="RESTDemoEndpointBehavior">
      <ipFilter/>
      <webHttp />
    </behavior>
  </endpointBehaviors>

and then your endpoints should be:

<endpoint address="rest" binding="webHttpBinding" contract="VLSCore2.Interfaces.IHmlApi" behaviorConfiguration="RESTDemoEndpointBehavior" />
    <endpoint address="soap" binding="basicHttpBinding" contract="VLSCore2.Interfaces.IHmlApi" behaviorConfiguration="SOAPDemoEndpointBehavior" />

Thanks alot this was spot on. Fair to say I think its important to set up all the correct endpoints for a service now!

Man I was struggling for a couple of hours already and I arrived here to noticed that I haven't changed the binding :))) I was using basic for http request from a mobile app... thumb up +

c# - Why does my WCF service give the message 'does not have a Binding...

c# wcf
Rectangle 27 1

I did some tests some time ago (see here) but take them with a grain of salt as that was a very "unscientifical" test (and was done with SL3).

You will have to test several different scenarios: for example a simple object with very large value inside their properties will be very different than a huge list of simple objects, or an object with a huge number of variables with very small values.

Creating the testing harness should not be difficult, I suggest you just do an "echo" service that returns the parameter without touching it. On the client you can simply measure the time between call and answer.

Do you still have the source code of your tests? You be great to take a look at it. I would really appreciate

sorry, the code is lost since a long time somewhere in a box... However it was pretty much trivial. You just need to switch the bindings to binary xml/etc. and use a Stopwatch object on the client side.

.net - Binary vs. Soap Binding - WCF Service Performance - Stack Overf...

.net silverlight wcf performance wcf-binding
Rectangle 27 6

You don't really have a JSON WCF service. You have a service which may or may not have an endpoint which can receive / send JSON data. The WSDL you're showing lists an endpoint (wsdl:port) which uses a SOAP-based binding (BasicHttpBinding). Endpoints which can "talk" JSON are defined with the WebHttpBinding, and have one specific behavior (WebHttpBehavior) applied to it - and they do not show up in the WSDL.

So, you cannot consume it with a client generated by a tool such as Add Service Reference or svcutil.exe. If you have the same contract in the client code, you can use a class such as ChannelFactory<T> or WebChannelFactory<T> to create a proxy to talk to the service, or you can handcraft the requests and send it to the service using a general-purpose HTTP client.

The sample code below shows how to consume a JSON endpoint with both the WebChannelFactory<T> and a "normal" HTTP client (WebClient).

public class StackOverflow_14945653
{
    [DataContract]
    public class Person
    {
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public int Age { get; set; }
        [DataMember]
        public Address Address { get; set; }
    }
    [DataContract]
    public class Address
    {
        [DataMember]
        public string Street;
        [DataMember]
        public string City;
        [DataMember]
        public string Zip;
    }
    [ServiceContract]
    public interface ITest
    {
        [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        void RegisterPerson(Person p);
        [WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        Person FindPerson(string name);
    }
    public class Service : ITest
    {
        private static List<Person> AllPeople = new List<Person>();

        public void RegisterPerson(Person p)
        {
            AllPeople.Add(p);
        }

        public Person FindPerson(string name)
        {
            return AllPeople.Where(p => p.Name == name).FirstOrDefault();
        }
    }
    public static void Test()
    {
        string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
        WebServiceHost host = new WebServiceHost(typeof(Service), new Uri(baseAddress));
        host.Open();
        Console.WriteLine("Host opened");

        Console.WriteLine("Accessing via WebChannelFactory<T>");
        WebChannelFactory<ITest> factory = new WebChannelFactory<ITest>(new Uri(baseAddress));
        ITest proxy = factory.CreateChannel();
        proxy.RegisterPerson(new Person
        {
            Name = "John Doe",
            Age = 32,
            Address = new Address
            {
                City = "Springfield",
                Street = "123 Main St",
                Zip = "12345"
            }
        });
        Console.WriteLine(proxy.FindPerson("John Doe").Age);
        Console.WriteLine();

        Console.WriteLine("Accessing via \"normal\" HTTP client");
        string jsonInput = "{'Name':'Jane Roe','Age':30,'Address':{'Street':'1 Wall St','City':'Springfield','Zip':'12346'}}".Replace('\'', '\"');
        WebClient c = new WebClient();
        c.Headers[HttpRequestHeader.ContentType] = "application/json";
        c.UploadString(baseAddress + "/RegisterPerson", jsonInput);

        c = new WebClient();
        Console.WriteLine(c.DownloadString(baseAddress + "/FindPerson?name=Jane Roe"));
        Console.WriteLine();

        Console.Write("Press ENTER to close the host");
        Console.ReadLine();
        host.Close();
    }
}

perhaps I am wrong, my coworker said it was a wcf json. But obviously it may not be that. I am confused by his wrong statement. So is there any sample code?

You should confirm what you have, and possibly ask for some sample code from whoever owns the service.

The code is helpful. One more question, the service is not self host. How to apprach the service? ITest is not recognized by intelisense.

You need to copy the interface from the service to the client.

Suppose I can't access the interface(developed by the third party),we just consume it from their server. we know the url, so what is the idea? Get the endpoint?

How to consume a json wcf service in C# - Stack Overflow

c# json wcf
Rectangle 27 1

You have to set the binding security to None.

<netTcpBinding >
    <binding name="MyServer" >
      <security mode="None" />
    </binding>
  </netTcpBinding>

Cannot call WCF service via net.tcp binding from IIS - Stack Overflow

wcf iis
Rectangle 27 10

I was receiving this error message, even though I had the max settings set within the binding of my WCF service config file:

<basicHttpBinding>
        <binding name="NewBinding1"
                 receiveTimeout="01:00:00"
                 sendTimeout="01:00:00"
                 maxBufferSize="2000000000"
                 maxReceivedMessageSize="2000000000">

                 <readerQuotas maxDepth="2000000000"
                      maxStringContentLength="2000000000"
                      maxArrayLength="2000000000" 
                      maxBytesPerRead="2000000000" 
                      maxNameTableCharCount="2000000000" />
        </binding>
</basicHttpBinding>

It seemed as though these binding settings weren't being applied, thus the following error message:

IIS7 - (413) Request Entity Too Large when connecting to the service.

name=""
<service>
web.config

fully qualified name of an implementation of a service contract

If that doesn't match, then the binding settings won't be applied!

<services>
  <!-- The namespace appears in the 'name' attribute -->
  <service name="Your.Namespace.ConcreteClassName">
    <endpoint address="http://localhost/YourService.svc"
      binding="basicHttpBinding" bindingConfiguration="NewBinding1"
      contract="Your.Namespace.IConcreteClassName" />
  </service>
</services>

Thanks for adding this solution! Indirectly solved my problem in that my contract name changed in dev but the change wasn't deployed to production properly. Checking these setting resolved my (413) Request Entity Too Large errors due to using default message size settings.

I'm really glad that this helped someone. I spent a good while on this so I hoped it would make someone's day less painful.

wcf - IIS7 - (413) Request Entity Too Large | uploadReadAheadSize - St...

wcf iis
Rectangle 27 10

I was receiving this error message, even though I had the max settings set within the binding of my WCF service config file:

<basicHttpBinding>
        <binding name="NewBinding1"
                 receiveTimeout="01:00:00"
                 sendTimeout="01:00:00"
                 maxBufferSize="2000000000"
                 maxReceivedMessageSize="2000000000">

                 <readerQuotas maxDepth="2000000000"
                      maxStringContentLength="2000000000"
                      maxArrayLength="2000000000" 
                      maxBytesPerRead="2000000000" 
                      maxNameTableCharCount="2000000000" />
        </binding>
</basicHttpBinding>

It seemed as though these binding settings weren't being applied, thus the following error message:

IIS7 - (413) Request Entity Too Large when connecting to the service.

name=""
<service>
web.config

fully qualified name of an implementation of a service contract

If that doesn't match, then the binding settings won't be applied!

<services>
  <!-- The namespace appears in the 'name' attribute -->
  <service name="Your.Namespace.ConcreteClassName">
    <endpoint address="http://localhost/YourService.svc"
      binding="basicHttpBinding" bindingConfiguration="NewBinding1"
      contract="Your.Namespace.IConcreteClassName" />
  </service>
</services>

Thanks for adding this solution! Indirectly solved my problem in that my contract name changed in dev but the change wasn't deployed to production properly. Checking these setting resolved my (413) Request Entity Too Large errors due to using default message size settings.

I'm really glad that this helped someone. I spent a good while on this so I hoped it would make someone's day less painful.

wcf - IIS7 - (413) Request Entity Too Large | uploadReadAheadSize - St...

wcf iis
Rectangle 27 15

It's possible that your WCF service is returning HTML. In this case, you'll want to set up a binding on the service side to return XML instead. However, this is unlikely: if it is the case, let me know and I'll make an edit with more details.

The more likely reason is that your service is throwing an error, which is returning an HTML error page. You can take a look at this blog post if you want details.

tl;dr: There are a few possible configurations for error pages. If you're hosting on IIS, you'll want to remove the <httpErrors> section from the WCF service's web.config file. If not, please provide details of your service hosting scenario and I can come up with an edit to match them.

Having seen your edit, you can see the full error being returned. Apache can't tell which service you want to call, and is throwing an error for that reason. The service will work fine once you have the correct endpoint - you're pointed at the wrong location. I unfortunately can't tell from the information available what the right location is, but either your action (currently null!) or the URL is incorrect.

The WEb service is a customers I don't have access to this, other than the url I am given to consume

Hi, just edited my response having seen the stack trace you put in. Looks like you need to change your endpoint address.

Hi, I checked with fiddler the app is sending the same url, albeit without the ?wsdl on the end. I can post the code for the project if it helps

?wsdl is important - it means the browser is just getting "Web Services Description Language" for the service, and not calling the service. The WSDL, if you learn to read it, will tell you the action to send. Add that action to your client's endpoint address, and you should have more luck with the service.

c# - The content type application/xml;charset=utf-8 of the response me...

c# wcf wcf-binding