I have a test WCF application that simply calls a method on the service layer. I am trying to test WCF timeouts but I can't seem to get the timeout to occur - I've added a thread sleep to simulate a long-running transaction.
I have set the sendTimeout="00:05:00" in the client binding configuration but this doesn't seem to have any affect when I add a 15 second thread sleep in the service call. i.e. the application waits 15 seconds and the result is successfully returned.
Client Configuration
<configuration>
<system.serviceModel>
<bindings>
<ws2007HttpBinding>
<binding name="WS2007HttpBinding_IBookService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:05:00" sendTimeout="00:05:00"
bypassProxyOnLocal="false" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
useDefaultWebProxy="true" allowCookies="false">
<security>
<transport realm="" />
</security>
</binding>
</ws2007HttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/bookservice/ws" binding="ws2007HttpBinding"
bindingConfiguration="WS2007HttpBinding_IBookService" contract="BookServiceReference.IBookService"
name="WS2007HttpBinding_IBookService" />
</client>
</system.serviceModel>
</configuration>
Service Configuration
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="MetaDataBehaviour" name="Service.BookService">
<clear />
<endpoint address="ws" binding="ws2007HttpBinding" contract="Service.IBookService"
listenUriMode="Explicit">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/bookservice" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MetaDataBehaviour">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
How do I get the timeout to occur?
Well 15 seconds is certainly less than 5 minutes (that is the value of sendTimeout="00:05:00").
If you want to simulate a sendTimeout violation which would raise a TimeoutException then you need to guarantee that the service call will not return until after the sendTimeout has been exceeded.
In your particular situation of 5 minutes then this will suffice:
public int MyServiceCall()
{
// Better bring something to read...
System.Threading.Thread.Sleep(300000);
return 0;
}
Related
Our WCF service is hosted in a Windows Service using net tcp binding with port 8090.
It works well for the most part, but from time to time, client applications fail to connect to the service, even if the service is still running and there are no apparent errors in the event log. The client application will get the following exception while connecting:
The open operation did not complete within the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout.
The client machine is still able to ping the server.
Restarting the windows service solves the problem, but users don't like it.
Any idea what could be happening here? I've read about the Net TCP Listener service and making sure the server has been patched. But I think that's only for net tcp binding hosted in IIS, and might not be applicable in my case.
Thanks!
Here's the service configuration:
<services>
<service behaviorConfiguration="behavior1" name="Tamer.Service.WcfService">
<endpoint binding="netTcpBinding" bindingConfiguration="netTcpLarge" name="endpoint1" contract="Tamer.Service.Library.IFundService" />
<endpoint binding="netTcpBinding" bindingConfiguration="netTcpLarge" name="endpoint2" contract="Tamer.Service.Library.IEntitlementService" />
<endpoint binding="netTcpBinding" bindingConfiguration="netTcpLarge" name="endpoint3" contract="Tamer.Service.Library.IReferenceDataService" />
<endpoint binding="netTcpBinding" bindingConfiguration="netTcpLarge" name="endpoint4" contract="Tamer.Service.Library.ITransactionService" />
<endpoint binding="netTcpBinding" bindingConfiguration="netTcpLarge" name="endpoint4" contract="Tamer.Service.Library.IDocumentService" />
<endpoint binding="netTcpBinding" bindingConfiguration="netTcpLarge" name="endpoint5" contract="Tamer.Service.Library.IFileStreaming" />
<endpoint binding="netTcpBinding" bindingConfiguration="netTcpLarge" name="endpoint6" contract="Tamer.Service.Library.IReportService" />
<endpoint address="net.tcp://localhost:8091/mex" binding="mexTcpBinding" name="mex" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="behavior1">
<serviceMetadata policyVersion="Policy15" />
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceThrottling maxConcurrentCalls="192" maxConcurrentSessions="192" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="netTcpLarge" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="01:00:00" sendTimeout="01:00:00" maxBufferPoolSize="524288"
maxReceivedMessageSize="2147483647" maxConnections="192" listenBacklog="100">
<!--listenBacklog="100"-->
<readerQuotas maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="None">
<message clientCredentialType="None"/>
<transport protectionLevel="None" clientCredentialType="None"/>
</security>
<!--reliableSession enabled="false"/-->
</binding>
</netTcpBinding>
</bindings>
I have hosted a WCF Service on IIS7 by creating a WCFService Application Project Type.
In WCF Service Solution, there are two Project. 1) Actual *WCFService* *and 2) WCFService Application* for hosting it in IIS7.0
1) Actual WCFService Project. app.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="DHDocuments.DService">
<endpoint address="" binding="wsHttpBinding"
contract="DHDocuments.IDService" >
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/DHDocuments/DService/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
2) WCFService Application web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<services>
<service name="DHDocuments.DService">
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration=""
name="basic"
contract="DHDocuments.IDService"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
In the IIS its being hosted. Its available at http://localhost:2004/DService.svc
Now Coming to the WCF Consuming Project,
I have added a Service Reference by Pointing to the http://localhost:2004/DService.svc. In my WCF Consuming client project this is the app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<client>
<endpoint address="http://localhost:2004/DService.svc"
binding="basicHttpBinding"
bindingConfiguration="basic1"
contract="WCFDHService.IDService"
name="basic" />
</client>
<bindings>
<basicHttpBinding>
<binding name="basic1" closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8"
transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384" maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName"
algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
This now complains:
The binding at system.serviceModel/bindings/basicHttpBinding does not have a configured binding named 'basic1'. This is an invalid value for bindingConfiguration
**
Can someone point what is being missed?
There is no problem when I have utilised wcf service directly by debug mode, without hosting it in IIS. I am sure, the binding config is getting error.
It appears that you have configured your services for metadata discovery with a mex endpoint:
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
Another endpoint in the service configuration is defined as wsHttpBinding:
<endpoint address="" binding="wsHttpBinding" contract="DHDocuments.IDService" >
I am guessing since mex is enabled the client proxy will generate a wsdl, however, you need to specify https if using transport security. Or add a endpoint for basicHttpBinding in your wcf service.
It seems like you are trying to access your service in the client proxy using a basicHttpBinding configuration but the service is not configured to accept or listen for such.
i use WCF with Code First (VS 2012, .NET 4.0, WCF 5). Everything works fine unless i want to transfer an large object. It contains a list of many other objects. Every object has only small content. If this list is longer than 127 objects, i get an exception:
The server did not provide a meaningful reply; this might be caused by
a contract mismatch, a premature session shutdown or an internal
server error.
I found that out by reducing column count in database (try and error).
I use the following configuration on the client:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_****_Service" closeTimeout="00:00:10"
openTimeout="00:00:10" receiveTimeout="00:05:00" sendTimeout="00:05:00"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8000/****" binding="netTcpBinding"
bindingConfiguration="****" contract="****"
name="NetTcpBinding_****Service">
<identity>
<userPrincipalName value="****" />
</identity>
</endpoint>
</client>
</system.serviceModel>
The server configuration looks as follows:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_****_Service" closeTimeout="00:00:10"
openTimeout="00:00:10" receiveTimeout="00:05:00" sendTimeout="00:05:00"
transferMode="Buffered" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxConnections="0" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="100000" maxStringContentLength="100000"
maxArrayLength="100000" maxBytesPerRead="100000" maxNameTableCharCount="100000" />
<reliableSession enabled="false" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="****">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_****_Service"
contract="****" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8000/****" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Please excuse the masking of some names. I need to avoid that one can draw inferences from these names about the project. :D
At first, set this property on server side (just for dev)
<serviceDebug includeExceptionDetailInFaults="true" />
that specifies whether to include managed exception information in the detail of SOAP faults returned to the client for debugging purposes.
It's sure there is something wrong when processing your request but you don't have any debug information. That's why you have to set this property. You can also turn on WCF Tracing but it's a bit more difficult.
WCF have many quotas : A quota is a hard limit that prevents the use of additional resources once the quota value is exceeded.
There are especially two quotas you need to be aware when sending large data : maxReceivedMessageSize and MaxItemsInObjectGraph.
I am currently trying to access a hosted WCF service using a locally hosted website, which is running successfully on the server (I am able to access the wsdl etc).
I am getting the error:
The message could not be processed. This is most likely because the action 'http://tempuri.org/IBetFriendService/SelectCustomerUsernamePasswordLogin' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.
I have increased both receiveTimeout and inactivityTimeout to 12:00:00 but i am still getting the error.
Web Config:
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IBetFriendService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="12:00:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="6553600" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="12:30:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://bet-friend.org.uk/BetFriendLibrary.BetFriendService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IBetFriendService1"
contract="BetFriendServiceReference2.IBetFriendService" name="WSHttpBinding_IBetFriendService1">
<identity>
<dns />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
WCF Config Snippet:
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="BetFriendLibrary.BetFriendService">
<endpoint address="" binding="wsHttpBinding" contract="BetFriendLibrary.IBetFriendService">
<identity>
<dns />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://bet-friend.org.uk/BetFriendLibrary.BetFriendService.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
I am also got same issues, once delete my all reference and then i will create the once again. the code working fine.. try you also... best of luck...
Thanks,
Ramesh Periyasamy
I've got a WCF Web MEthod that takes in an XElement object as a parameter. For one of my XML files (sized at 600KB or so) this works just fine, however, for this bigger XML file (about 5MB) I get a CommunicationException right away.
I've already increased the message sizes for my binding. Below is the ServiceModel section of my web.config:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="BIMIntegrationWS.metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="BIMIntegrationWS.IntegrationService.customBinding0"
closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:10:00">
<binaryMessageEncoding>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binaryMessageEncoding>
<httpTransport maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" />
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="BIMIntegrationWS.BIMIntegrationWS" behaviorConfiguration="BIMIntegrationWS.metadataBehavior">
<endpoint address="" binding="customBinding" bindingConfiguration="BIMIntegrationWS.IntegrationService.customBinding0"
contract="BIMIntegrationWS.IBIMIntegrationService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
On the client, my ClientConfig looks like this:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_IBIMIntegrationService">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:1895/IntegrationService.svc"
binding="customBinding" bindingConfiguration="CustomBinding_IBIMIntegrationService"
contract="BIMIntegrationService.IBIMIntegrationService" name="customBindingEndpoint" />
</client>
</system.serviceModel>
Thanks in advance!
try to add following snippet into your web.config for the service application:
<system.web>
<httpRuntime maxRequestLength="16384" /> <!-- 16MB -->
</system.web>
When you host the service in web server you also have to tweak allowed request size for the web server.
Best regards,
Ladislav
Maybe your XElement has too many nodes/child elements, and you need to set the maxItemsInObjectGraph attribute under dataContractSerializer to something larger?
You probably need to change the values of the attributes of the <readerQuotas /> sub element of <binaryMessageEncoding />.
For more information, see:
http://msdn.microsoft.com/en-us/library/ms731325.aspx
http://forums.silverlight.net/forums/p/88704/205040.aspx
Update:
Can you try to increase the maxAllowedContentLength as described here:
http://social.msdn.microsoft.com/Forums/en/wcf/thread/e6e21132-ad3f-4135-8ab9-77923b099907
Do you know how to turn off VS host and to just deploy to IIS and give it a ping. Normal IIS 7 on your dev box will do just fine. You can still attach debugger etc, just won't have instantaneous F5 gratification but since your ocode is not dying on startup you don't need to see if from the fist line anyway :-)
If you would need to attach very early you could could make a mimimal method that doesn't tounch anything at all and just returns int constnat - just to bring up app pool so you can attach.