Is my app.config working? Truncated data - c#

This is my first WCF service project writing both client and server side. I'm from a Windows Forms background.
I think I've been having problems with packet/receive buffer size but I don't have a clue how to test whether my app.config is working correctly or what I've done wrong.
The client project's app.config is set as follows and it's testproj.exe.config reflects the contents correctly
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IPulseWebService"
closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8"
useDefaultWebProxy="true">
<readerQuotas
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxDepth="2147483647"
maxNameTableCharCount="2147483647"
maxStringContentLength="2147483647" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="blah"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IPulseWebService"
contract="ServiceReference1.IPulseWebService" name="WSHttpBinding_IPulseWebService">
<identity>
<dns value="localhst" />
</identity>
</endpoint>
</client>
</system.serviceModel>
My web service's webservice.dll.config contains the following service.serviceModel section
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IPulseWebService"
closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8"
useDefaultWebProxy="true">
<readerQuotas
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxDepth="2147483647"
maxNameTableCharCount="2147483647"
maxStringContentLength="2147483647" />
</binding>
</wsHttpBinding>
<basicHttpBinding>
<binding name="BasicHttpBinding_IPulseWebService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
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>
<services>
<service name="SmartcentreWcfLib.PulseWebService">
<host>
<baseAddresses>
<add baseAddress="http://l0calhost:8732/Design_Time_Addresses/SmartcentreWcfLib/PulseWebService/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IPulseWebService"
contract="SmartcentreWcfLib.IPulseWebService">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="l0calhost" />
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</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>
</system.serviceModel>
In my server side wcf dll, I have the following function just as a test to return some rows of data. Each row is a set of key/value pairs stored in an Dictionary. Each object should be a simple byte[] or variable type.
List<IDictionary<string, object>> IAuditV1.ReadAuditForStaffMember(long staffId, DateTime startDate,
DateTime endDate, Int32 recordCount)
{
List<TableAdminAudit> tempResult = DatabaseInterface.Instance.AuditQueries.ReadAdminAudit(staffId, startDate,
endDate, recordCount);
return tempResult.Select(record => record.PrepareForWebInterface()).Cast<IDictionary<string, object>>().ToList();
}// function
In my client application I am running the following loop, which simply increments the number of received records.
Int32 totalRecords = 0;
while (true)
{
results = client.ReadAuditForStaffMember(1, DateTime.MinValue, DateTime.Now, totalRecords);
totalRecords += 10; //results.Length;
if (totalRecords == 0) break;
}
On the 3rd loop when the returned buffer reaches 30 records in size I receive the following error message.
I looked up the error and forums suggested it relates to the connection closing before the whole data had been received so change the various buffer sizes etc. As you can see from my config files, I've upped all the values I'm aware of to 2147483647 but it's not worked.
So I don't know where to go from here. Can anybody help please?
System.ServiceModel.CommunicationException occurred
HResult=-2146233087
Message=An error occurred while receiving the HTTP response to blah2/Design_Time_Addresses/SmartcentreWcfLib/PulseWebService/. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
Source=mscorlib
StackTrace:
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)
at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.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 WcfTester.ServiceReference1.IPulseWebService.ReadAuditForStaffMember(Int64 staffId, DateTime startDate, DateTime endDate, Int32 startIndex)
at WcfTester.ServiceReference1.PulseWebServiceClient.ReadAuditForStaffMember(Int64 staffId, DateTime startDate, DateTime endDate, Int32 startIndex) in W:\Projects\pulse.smartcentre.root\pulse.smartcentre\WcfTester\Service References\ServiceReference1\Reference.cs:line 481
at WcfTester.Program.Main(String[] args) in W:\Projects\pulse.smartcentre.root\pulse.smartcentre\WcfTester\Program.cs:line 40
InnerException: System.Net.WebException
HResult=-2146233079
Message=The underlying connection was closed: An unexpected error occurred on a receive.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
InnerException: System.IO.IOException
HResult=-2146232800
Message=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
Source=System
StackTrace:
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
InnerException: System.Net.Sockets.SocketException
HResult=-2147467259
Message=An existing connection was forcibly closed by the remote host
Source=System
ErrorCode=10054
NativeErrorCode=10054
StackTrace:
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
InnerException:**

The file something.dll.config is never used. You need to copy those settings into the web.config or servicehost.exe.config file.
This is how .NET has worked since Day 1, and is not specific to WCF. Consider that a given DLL can be used by multiple "executables", and each of these may have different settings for the DLL.

Related

WCF Service - Message / Object size related

I have wcf service (S1) as client and another Wcf service(S2) as server. S1 consume S2 over net.tcp. S2 has one operation, which return a complex object with most of it's contents are string. The average size of this object is between 7-8 MB.
Recently I had to add more string contents to the actual object graph. This cause S2 to return following error
The socket connection was aborted. This could be caused by an error
processing your message or a receive timeout being exceeded by the
remote host, or an underlying network resource issue. Local socket
timeout was '00:05:00'. System.Net.Sockets.SocketException
(0x80004005): An existing connection was forcibly closed by the remote
host at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32
offset, Int32 size, SocketFlags socketFlags) at
System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer,
Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
However, everything works as expected when I remove some of the string contents from the object graph.
After doing bit of a homework,I was managed to land on a conclusion that, it has something to do with the size of the returned object. This made me to revise my client and service configuration/quota's.
However, I have no luck even after modifying the client and service especially size related attributes.
Can someone guide me on this? Please ask me for more information if needed.
Thanks in advance.
Client (S1)
<netTcpBinding>
<binding name="NetTcp" closeTimeout="00:05:00"
openTimeout="00:05:00" receiveTimeout="00:10:00" sendTimeout="00:05:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="2147483647"
maxBufferSize="2147483647" maxConnections="10" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
<client>
<endpoint address="net.tcp://xxxxxxxx/xxxxxxService"
binding="netTcpBinding" bindingConfiguration="NetTcp" behaviorConfiguration="RBehavior"
contract="IService" name="NetTcp" />
</client>
<services/>
<behaviors>
<serviceBehaviors>
<behavior name="NSBehavior">
<etwTracking profileName="EndToEndMonitoringProfile"/>
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="RBehavior">
**<dataContractSerializer maxItemsInObjectGraph="2147483647" />**
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Server (S2)
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="netTcp" closeTimeout="00:03:00"
openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="20000000"
maxBufferSize="20000000" maxConnections="10" maxReceivedMessageSize="20000000">
<readerQuotas maxDepth="32" maxStringContentLength="20000000"
maxArrayLength="20000000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="Engine.Rules"
behaviorConfiguration="REServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://xxxxx:8005/Service"/>
</baseAddresses>
</host>
<endpoint address=""
binding="netTcpBinding" bindingConfiguration="netTcp"
contract="Ixxxx" />
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="REServiceBehavior">
<serviceMetadata httpGetEnabled="false"/>
**<dataContractSerializer maxItemsInObjectGraph="2147483647"/>**
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling maxConcurrentSessions="1000"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Update: As per #ErikFunkenbusch's sensible support, I am attaching service trace information.
<ExceptionString>System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:05:00'. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
--- End of inner exception stack trace ---</ExceptionString>
<InnerException>
<ExceptionType>System.Net.Sockets.SocketException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>An existing connection was forcibly closed by the remote host</Message>
<StackTrace>
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
</StackTrace>
<ExceptionString>System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)</ExceptionString>
<NativeErrorCode>2746</NativeErrorCode>
</InnerException>
</Exception>
Have you tried increasing the send and receive timeout values? You're sending a lot of data over the wire (7-8MB) and 5 seconds may not be enough time to complete that transaction. Try setting them to something like 30 seconds and then working from there.
E:
<binding name="netTcp" closeTimeout="00:30:00"
openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00">
That is what I'm referring to, specifically.

The remote server returned an unexpected response: (413) Request Entity Too Large.

I'm trying to build a WCF Application service, using FW4.0.
My service work correctly when transferring EntiryFramework object between Server and client. But I'm having problem passing EF object from Client to Server.
Here some more detail about my environment:
- The service is running in debug mode locally on IIS
- I'm running all this on my Windows 7
- I'm using Visual Studio 2010 on FW4.0
I'm trying to send a object (tblClient) to server to save the record, but a keep having the error (413) Request Entity Too Large.
Here the full stack:
System.ServiceModel.ProtocolException occurred
HResult=-2146233087
Message=The remote server returned an unexpected response: (413) Request Entity Too Large.
Source=mscorlib
StackTrace:
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory`1.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.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 ClientApp.ServiceReference1.IService.SaveClient(tblClient client)
at ClientApp.ServiceReference1.ServiceClient.SaveClient(tblClient client) in C:\dufh\WPF Project\ClientApp\Service References\ServiceReference1\Reference.vb:line 2383
at ClientApp.ViewModel.ClientViewModel.SaveClient() in C:\dufh\WPF Project\ClientApp\ViewModel\ClientViewModel.vb:line 48
InnerException: System.Net.WebException
HResult=-2146233079
Message=The remote server returned an error: (413) Request Entity Too Large.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
InnerException:
I've do some research and all point to the maxBufferSize and/or maxBufferPoolSize and/or maxReceivedMessageSize witch is not large enough in the Client config App.Config. So I inscresed them to maximum value :
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
But still the error remain.
Here my full Client App.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="MVVM Sampling"/>
</sharedListeners>
</system.diagnostics>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"/>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:7803/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService"
name="BasicHttpBinding_IService" />
</client>
</system.serviceModel>
</configuration>
and the full Web.Config WCF service Web.Config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
<readerQuotas maxDepth="200" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
</binding>
</basicHttpBinding>
</bindings>
<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>
<connectionStrings>
<add name="MaitreEntities" connectionString="metadata=res://*/Schemat.csdl|res://*/Schemat.ssdl|res://*/Schemat.msl;provider=System.Data.SqlClient;provider connection string="data source=INFOFILE2\SQL2008R2;initial catalog=0001ConneryFerland;user id=sa;password=kermit80;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
Any help would be very welcome :-)
For the record
I think I got it.
The Web.Config from the service does not have the binding information.
I placed this info in it, and voila!
<bindings>
<basicHttpBinding>
<binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
Note here that the binding did not have a name specified.
You don't have an explicit endpoint (meaning one defined in your config file) for your service, so the binding configuration you declared ("BasicHttpBinding_IService") isn't being used. WCF is providing a default endpoint along with a default binding (basicHttpBinding unless you overrode it in the protocolMapping section of the config file).
You have two ways to resolve this in your service's config file:
You can make the "BasicHttpBinding_IService" configuration the default by removing the name attribute:
<binding maxBufferPoolSize="2147483647".....
Or you define an endpoint explicitly in the config and assign your binding configuration to the bindingConfiguration attribute of the endpoint.
<services>
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService"
contract="ServiceReference1.IService" />
</services>
If you create custom binding e.g. MybasicBinding,
<basicHttpBinding>
<binding name="MybasicBinding" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="32" maxBytesPerRead="200000000"
maxArrayLength="200000000" maxStringContentLength="200000000" />
</binding>
</basicHttpBinding>
To avoid the 413 error, Do not foreget to Specify the bindingConfiguration="MybasicBinding" for service endpointas,
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MybasicBinding" contract="WCFService.IService" />
Another way to fix this and have a better look at web.config file, is to edit the web.config file with the "Microsoft Service Configuration Editor" (C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\SvcConfigEditor.exe)
if no binding is specified and httpsgetenabled is true then you may need to set basichttpsbinding in your service application's web.config
<bindings>
<basicHttpsBinding>
<binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpsBinding>
I was getting this error. I discovered that I had created the binding configuration, but failed to set the endpoint to that configuration. Therefore, the endpoint was using an unnamed binding configuration with the default settings. So, maxReceivedMessageSize was 65k.
This can also be due to IIS restriction.
IIS Manager-> Select your application-> Features Veiw->Request Filtering->Edit Feature Settings->Maximum Allowed Content Length 30000000(28.6M)-> Increase the value

WCF Client and Service Endpoints Using the Same Binding

I feel like this has probably been answered and maybe I am not searching with the right terms.
I have a WCF service that acting like a proxy. It is a middle man for two services that normally can talk to each other, but now go through this new service.
Old:
A -> B
New:
A -> MM -> B
I need to expose the same contract as a service endpoint (for "A" to talk to "MM") and as a client endpoint (for "MM" to talk to "B").
Can these two share a binding configuration and just give the endpoints different names? Or is there a better way to handle this scenario?
(inside of <system.serviceModel> tag)
<client>
<endpoint address="http://<remoteaddress>/" binding="basicHttpBinding"
bindingConfiguration="MyBinding" contract="IService" name="ToB" />
</client>
<services>
<service behaviorConfiguration="Behavior" name="Service">
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="MyBinding" name="FromA" contract="IService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/MyService" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="MyBinding" closeTimeout="00:15:00" openTimeout="00:15:00"
receiveTimeout="00:15:00" sendTimeout="00:15:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2048000000" maxBufferPoolSize="2048000000"
maxReceivedMessageSize="2048000000" messageEncoding="Text"
textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="4065536" maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName"
algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
Edit:
The error message with this setup is:
com.vsp.cal.webservice.external.SystemFault
Stack:
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
A change in name is not enough to uniquely define an endpoint. Instead goes back to the old "ABC" - address, binding, contract. At least one of those must be different to uniquely define a new endpoint.
http://msdn.microsoft.com/en-us/library/ms733107(v=vs.100).aspx
Does this help?
Thank you to everyone who looked this over and tried to help!
In the end it was not the configuration, but a stupid coding error. The cryptic error message is the response from the other side (a Java web service). It wasn't happy because I was sending a null object due to a failed cast.
So the answer is that this configuration DOES WORK when you don't code like an idiot.

c# WCF Service return collection

I've created wcf service and everything works correctly but when i try to return Type[] (i got it from Assembly.GetTypes()) i have following exception:
System.ServiceModel.CommunicationException: The underlying connection was closed: The connection was closed unexpectedly.
---> System.Net.WebException: The underlying connection was closed: The connection was closed unexpectedly.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
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.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 ConsoleApplication1.ServiceReference1.IWcfAssembly.GetAssemblyTypes(String a)
at ConsoleApplication1.ServiceReference1.WcfAssemblyClient.GetAssemblyTypes(String a) in D:\Projekty\ConsoleApplication1\ConsoleApplication1\Service References\ServiceReference1\Reference.cs:line 50
at ConsoleApplication1.Program.Main(String[] args) in D:\Projekty\ConsoleApplication1\ConsoleApplication1\Program.cs:line 17
I thought it might be maxItemsInObjectGraph property or maxArrayLenght (and similar) but it didn't help. Still got the same exception. Maybe I did something wrong with the property declaration?
this is my client config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IWcfAssembly" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="4096" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:57040/WcfAssembly.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IWcfAssembly" contract="ServiceReference1.IWcfAssembly"
name="BasicHttpBinding_IWcfAssembly" />
</client>
</system.serviceModel>
</configuration>
and this is my service config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IWcfAssembly" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"
maxBufferPoolSize="52428899">
<readerQuotas maxDepth="128"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="4096"
maxNameTableCharCount="2147483647" />
<security mode="None"/>
</binding>
</basicHttpBinding>
</bindings>
<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>
I have also added [ServiceBehavior(MaxItemsInObjectGraph = int.MaxValue)] as a class attribute. I had it in my service config before but this is one of tries.
Do you have any ideas guys? Why the array returned from Assembly.GetTypes() causes such error? (big array of int[] works OK)
The problem is that the System.RunTimeType is not serialize (which is in the internal implementation of Type)
using this mock:
void Main()
{
var dto = new MyDto();
dto.Tada = new Type[] { this.GetType() };
DataContractSerializer ser =
new DataContractSerializer(typeof(MyDto));
var ms = new MemoryStream();
ser.WriteObject(ms, dto);
ms.Dump();
dto.Dump();
}
public class MyDto
{
public Type[] Tada { get; set; }
}
Throws:
SerializationException: Type 'System.RuntimeType' with data contract
name 'RuntimeType:http://schemas.datacontract.org/2004/07/System' is
not expected. Consider using a DataContractResolver or add any types
not known statically to the list of known types - for example, by
using the KnownTypeAttribute attribute or by adding them to the list
of known types passed to DataContractSerializer.
Which makes sense because RunTimeType is internal (Type itself is abstract). You have to come up with your own serialized type that can convey the info you want.

An existing connection was forcibly closed by the remote host

My service's app.config
<system.serviceModel>
<client>
<endpoint name="DataLocal" address="net.tcp://SomeAddress" binding="netTcpBinding" contract="ISomeContract" bindingConfiguration="TcpCustomSecurity" behaviorConfiguration="SecureBehaviorName">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</client>
<services>
<service name="SomeService">
<host>
<baseAddresses>
<add baseAddress="http://SomeService" />
<add baseAddress="net.tcp://SomeService" />
</baseAddresses>
</host>
<endpoint name="SomeService_Normal" address="Secure" binding="netTcpBinding" contract="ISomeService" bindingConfiguration="TcpNormal"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="TcpNormal" transferMode="Buffered" receiveTimeout="24.20:31:23.6470000">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None" />
</binding>
<binding name="TcpCustomSecurity" transferMode="Buffered" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="24.20:31:23.6470000" sendTimeout="00:01:00" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="SecureBehaviorName">
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="None"/>
</serviceCertificate>
</clientCredentials>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
Following are the stack statements for the error i am getting..
> System.dll!System.Net.Sockets.Socket.Send(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags) + 0x5a bytes
System.ServiceModel.dll!System.ServiceModel.Channels.SocketConnection.Write(byte[] buffer, int offset, int size, bool immediate, System.TimeSpan timeout) + 0xa7 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.SocketConnection.Write(byte[] buffer, int offset, int size, bool immediate, System.TimeSpan timeout, System.ServiceModel.Channels.BufferManager bufferManager) + 0x34 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.BufferedConnection.WriteNow(byte[] buffer, int offset, int size, System.TimeSpan timeout, System.ServiceModel.Channels.BufferManager bufferManager) + 0x90 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.BufferedConnection.Write(byte[] buffer, int offset, int size, bool immediate, System.TimeSpan timeout, System.ServiceModel.Channels.BufferManager bufferManager) + 0x47 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.FramingDuplexSessionChannel.OnSend(System.ServiceModel.Channels.Message message, System.TimeSpan timeout) + 0x115 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.OutputChannel.Send(System.ServiceModel.Channels.Message message, System.TimeSpan timeout) + 0x81 bytes
System.ServiceModel.dll!System.ServiceModel.Dispatcher.DuplexChannelBinder.Request(System.ServiceModel.Channels.Message message, System.TimeSpan timeout) + 0x154 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannel.Call(string action, bool oneway, System.ServiceModel.Dispatcher.ProxyOperationRuntime operation, object[] ins, object[] outs, System.TimeSpan timeout) + 0x206 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(System.Runtime.Remoting.Messaging.IMethodCallMessage methodCall, System.ServiceModel.Dispatcher.ProxyOperationRuntime operation) + 0x59 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannelProxy.Invoke(System.Runtime.Remoting.Messaging.IMessage message) + 0x65 bytes
mscorlib.dll!System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(ref System.Runtime.Remoting.Proxies.MessageData msgData, int type) + 0xee bytes
// First the service call in the above stack...
Service Behavior is this:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
The error occured after few hours of constant testing...unable to reproduce it while debugging..
EDIT:
I've got the tracing results thanks to Dejan...
on the first occurance of error i get this message: Maximum number of pending connections has been reached.
on the second occurance i get this message : The system hit the limit set for throttle 'MaxConcurrentConnections'.Limit for this throttle was set to 200.Throttle value can be changed by modifying attribute 'maxConcurrentSessions' in service throttle element.
So for the second message i did this:
and assigned this service behavior to the service. do i need to set the maxConnections on the binding for the first message.Moreover, which is the root cause for the problem , first one or second one or both. Because in the subsequent messages i always get the second message.
Please guide to update my app.config to avoid such scenario.
UPDATE
I've got the tracing results...
on the first occurance i get this message: Maximum number of pending connections has been reached.
on the second occurance i get this message : The system hit the limit set for throttle 'MaxConcurrentConnections'.Limit for this throttle was set to 200.Throttle value can be changed by modifying attribute 'maxConcurrentSessions' in service throttle element.
So for the second message i did this:
<serviceBehaviors>
<behavior name="tcpNormalBehavior">
<serviceThrottling maxConcurrentSessions="800" maxConcurrentInstances="800" maxConcurrentCalls="200" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
and assigned this service behavior to the service.
do i need to set the maxConnections on the binding for the first message.Moreover, which is the root cause for the problem , first one or second one or both. Because in the subsequent messages i always get the second message.
Please guide.
There is a possibilty that you have an unhandled exception such as stack overflow somewhere in your WCF service. If I get it correctly, the service works but stops working after a few hours.
The first step to debugging a WCF service is WCF Tracing. Enable it, try to test your service and after it stops working again, there should be a trace entry in the .svclog file.
EDIT
Regarding your updated question: You get that exception because you are not closing the connection from the client side after you're done with the call. Try refactoring your code so calls to WCF look like this:
WCFProxy clientProxy = null;
try
{
clientProxy = new WCFProxy();
clientProxy.SomeCall();
clientProxy.Close();
}
catch (Exception)
{
if (clientProxy != null)
{
clientProxy.Abort();
}
throw;
}
and then see if it will cause problems.

Categories

Resources