I'm trying to use WCF and NetMessagingBinding to publish messages into a Windows Service Service Bus Topic and for large messages - at least 603kb - the push operation is throwing the following error:
System.ServiceModel.QuotaExceededException: The maximum message size quota for outgoing messages (262144) has been exceeded.
Server stack trace:
at System.Runtime.BufferedOutputStream.WriteCore(Byte[] buffer, Int32 offset, Int32 size)
at System.Xml.XmlBinaryNodeWriter.FlushBuffer()
at System.Xml.XmlStreamNodeWriter.GetBuffer(Int32 count, Int32& offset)
at System.Xml.XmlStreamNodeWriter.UnsafeWriteUTF8Chars(Char* chars, Int32 charCount)
at System.Xml.XmlBinaryNodeWriter.UnsafeWriteText(Char* chars, Int32 charCount)
at System.Xml.XmlBinaryNodeWriter.WriteText(String value)
at System.Xml.XmlBaseWriter.WriteString(String value)
(...)
From the error I noticed that the problem is not the serialization and therefore I can't use a Message Formatter. What else can I use to overcome this exception? Any thoughts?
Thanks in advance!
This issue was solved by replacing the netMessagingBinding by a customBinding which uses the netMessagingTransport.
1- Add netMessagingTransport as a binding extension:
<bindingElementExtensions>
<add name="netMessagingTransport" type="Microsoft.ServiceBus.Messaging.Configuration.NetMessagingTransportExtensionElement, Microsoft.ServiceBus, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</bindingElementExtensions>
2- Add a custom binding:
<customBinding>
<binding name="sbBindingConfiguration" sendTimeout="00:01:00" receiveTimeout="00:01:00" openTimeout="00:01:00">
<binaryMessageEncoding>
<readerQuotas maxDepth="100000000" maxStringContentLength="100000000"
maxArrayLength="100000000" maxBytesPerRead="100000000" maxNameTableCharCount="100000000"/>
</binaryMessageEncoding>
<netMessagingTransport manualAddressing="false" maxBufferPoolSize="100000" maxReceivedMessageSize="100000000">
<transportSettings batchFlushInterval="00:00:00"/>
</netMessagingTransport>
</binding>
</customBinding>
3- Use the attribute maxReceivedMessageSize to define a value that suits the size of messages that will be exchanged
4- Reference your custom binding in the endpoint
<endpoint (...) binding="customBinding" bindingConfiguration="sbBindingConfiguration" />
Related
I'm using a WCF client and call a method GetEmployeeId. In GetEmployeeId method, I have a return statement.
return employeeid;
When I add a breakpoint on employeeid - it has 4984 id's.
Once I click on continue, I am getting the following error:
Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.
Inner Exception:
The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
In the client and service, I am using:
<bindings>
<basicHttpBinding >
<binding name="MybasicHttpBinding"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647"
maxArrayLength="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
and the endpoint address is :
<endpoint
address="http://localhost/EmployeeService/Service.svc"
binding="basicHttpBinding"
bindingConfiguration="MybasicHttpBinding"
contract="Employee.Contract.IEmployee" >
The number of IDs being less than the max size quota is easily possible. If you have, for example, a very basic ID that looks like
5
then even though it's "1" record, it takes up 26 bytes of "size".
I have services that return large objects, default transfermode (buffered) doesn't suit to our requirements.
Actually the service is written already and the project team is experiencing out of memory exceptions and slow performance intermittently. Now this needs to be fixed with some patching, rewrting all the services is not an option as the project team is nearing a delivery.
I have an understanding that changing the transfermode to StreamedResponse/Streamed may help in a big way + choosing net.tcp instead of http bindings (intranet application with thick client). I need to know whether I will get benefit for all the operationcontracts or only those, which return Stream/Message.
I created a little sample to check if it has any impact on other return types (DataTable/DataSet) and it seems it effects all the return types including DataTable/DataSet. I checked WCF HttpTransport: streamed vs buffered TransferMode and looks like the same behavior is experienced by others as well.
The only thing missing here is some concrete documentation which clearly states that it effects all the operationcontracts irrespective of return type. I need some references so that I can push my recommendation for this chnage.
Please do not suggest not to return DataTable/DataSet from the services; I know its a bad-bad practice and should be avoided all the times but in this case the services were already there and I can't ask them to change everything at this moment.
Update:
My perception is based on following test
My interface
[ServiceContract]
public interface IMediaManager
{
[OperationContract]
Stream Play(int mediaId);
[OperationContract]
DataSet GetJunk();
}
My Implementation
public class MediaManager : IMediaManager
{
public Stream Play(int mediaId)
{
String path = GetMedia(mediaId);
FileStream fStream = new FileStream(path, FileMode.Open, FileAccess.Read,FileShare.Read);
return fStream;
}
public DataSet GetJunk()
{
return GetLargeJunkDataSet20PlusMegs();
}
}
Hosted over IIS - Non Http WAS, Server Configuration File (Tags stripped off, only relevant ones)
<system.serviceModel>
<services>
<service name="MediaService.MediaManager" behaviorConfiguration="MediaServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9876/MediaService/MediaManager.svc" />
</baseAddresses>
</host>
<endpoint address="" binding="customBinding"
bindingConfiguration="StreamedTcpBinding" name="MediaManagerTcp"
contract="MediaService.IMediaManager" />
<endpoint address="mexTcp" binding="mexTcpBinding" name="mexTcp"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<customBinding>
<binding name="StreamedTcpBinding" sendTimeout="00:10:00" receiveTimeout="00:10:00">
<binaryMessageEncoding />
<tcpTransport transferMode="Streamed" portSharingEnabled="true" />
</binding>
</customBinding>
</bindings>
Client Configuration File (Only relevant tags)
<binding name="MediaManagerTcp" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
transferMode="Streamed" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="2147483647"
***maxBufferSize="1001"*** maxConnections="10" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
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>
If you see above, the maxBufferSize is 1001 bytes, however the actual message would be 20+ mb. This makes me think the Streamed is working for DataSet as well (everything, not only limited to Stream and Message). I hope my interpretation is correct of maxBufferSize (its the maximum size which will be received in one chunk).
I must also add that the same method fails if I switch to Buffered mode.
I hope my analysis makes sense, if not clear then please let me know and I shall try again?
I will repeat my question again so that it doesn't get lost :)
The only thing missing here is some concrete documentation which clearly states that it effects all the operationcontracts irrespective of return type. I need some references/experiences so that I can push my recommendation for this chnage.
Any help will be much appreciated!
Thanks,
A
Finally found something relevant.
The DataSet is an inherited child of IXMLSerializable, hence its a candidate for streaming. Following is picked from MSDN (Streaming Message Transfer)
Operations that occur across a streamed transport can have a contract with at most one input or output parameter. That parameter corresponds to the entire body of the message and must be a Message, a derived type of Stream, or an IXmlSerializable implementation. Having a return value for an operation is equivalent to having an output parameter.
and DataSet is an implementation of IXmlSerializable . DataSet's definition
[SerializableAttribute]
public class DataSet : MarshalByValueComponent, IListSource,
IXmlSerializable, ISupportInitializeNotification, ISupportInitialize,ISerializable
Thanks,
A
I am consuming wcf service in Wpf application. I have to save an image which is 185 Kb in size. Problem is every time, i try to save it i got this message
Remote server returned an unexpected response. (413) Requested entity too large.
Here is my binding on client side
<binding name="BasicHttpBinding_IHRMEmployeeDef" maxBufferPoolSize="2147483646"
maxBufferSize="2147483646" maxReceivedMessageSize="2147483646" >
<readerQuotas maxDepth="525288" maxStringContentLength="525288" maxArrayLength="525288"
maxBytesPerRead="525288" maxNameTableCharCount="525288" />
</binding>
AND
<endpoint address="http://localhost:1714/PAYROLL/Setup/HRMEmployeeDef.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IHRMEmployeeDef"
contract="Service_EmployeeDef.IHRMEmployeeDef" name="BasicHttpBinding_IHRMEmployeeDef" />
Any Suggestions
I found the solution... By setting maxReceivedMessageSize In my Web.Config
I'm working over WCF and it worked fine on localhost. After I placed it on the production server, it thows an exception
The requested service, 'http://global-kazway.kz/Service1.svc' could
not be activated. See the server's diagnostic trace logs for more
information
I'm new in Services and have been trying to solve this problem for almost 3 hours.
Here is the App.config of the client;
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections></configSections>
<connectionStrings>
<add name="TestProject.Properties.Settings.DBConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\1\Documents\visual studio 2010\Projects\TestProject\TestProject\AppData\DB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" /><add name="DBEntities" connectionString="metadata=res://*/DBModel.csdl|res://*/DBModel.ssdl|res://*/DBModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=C:\Users\1\Documents\visual studio 2010\Projects\TestProject\TestProject\AppData\DB.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /><add name="DBEntities1" connectionString="metadata=res://*/DBModel.csdl|res://*/DBModel.ssdl|res://*/DBModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\AppData\DB.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" 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>
<client>
<endpoint address="http://global-kazway.kz/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="kazwayServiceReference.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
First step in troubleshooting a WCF application is to bring up a browser and type in the service URI. So based on the client: you'd navigate to http://global-kazway.kz/Service1.svc
Now see what kind of results you get. Exception? The service screen? Usually you can get your best information from this screen! Sometimes it points out what your issue is such as missing a behavior.
Compare your web.config with the deployed web.config entries. You may find something there as well. Finally you may just have to manage security on your folder. But the browser display could spell everything out for you very clearly.
I'm working on a project and I faced the same problem.
When I checked the Event Viewer to trace the error, I found where the problem was.
Event Viewer message:
Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/7540993
Exception: System.ServiceModel.ServiceActivationException: The service '/CODWebService/Service1.svc' cannot be activated due to an exception during compilation. The exception message is: Memory gates checking failed because the free memory (164065280 bytes) is less than 5% of total memory. As a result, the service will not be available for incoming requests. To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.. ---> System.InsufficientMemoryException: Memory gates checking failed because the free memory (164065280 bytes) is less than 5% of total memory. As a result, the service will not be available for incoming requests. To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.
Then I added the below code to my service's web.config file.
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="1" />
This element should be placed in <system.serviceModel>
i'm working over WCF and it worked fine on localhost.After i placed it to the production server, it thows me an exception "The requested service, 'http://global-kazway.kz/Service1.svc' could not be activated. See the server's diagnostic trace logs for more information"
This MSDN article describes how to configure tracing on the server. Once you've done that you can look at the server's diagnostic trace logs, and will likely find the problem.
To have a more detailed description of the error please insert this code in your web.config file of the service:-
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
Then use this service behavior in your service like this :-
<service name="MyService" behaviorConfiguration="MyServiceBehavior" >
<endpoint address="" binding="basicHttpBinding" xxxx="" xxxxx="" xxxxx="" xxxx="" xxxx="" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
<host>
<baseAddresses>
<add baseAddress="http://ServerAddress:AnyPortIfspecified/VirtualDirname"/>
</baseAddresses>
</host>
</service>
This will give you a detailed description of the error.
The second thing that you may try is check this:-
<host>
<baseAddresses>
<add baseAddress="http://ServerAddress:AnyPortIf specified/VirtualDir name"/>
</baseAddresses>
</host>
make sure your base address is not localhost.
TC
I was able to resolve the issue by following below steps using Visual Studio 2013:
Go to your project folder where you have your *.svc file
Right Click *.svc file --> View in browser
Validate if you are able to browse the service
Go to your project folder where you have your app.config file or where you want to consume the service.
Right click project-->Add-->Service Reference
Click Discover-->Under Services Select Service-->Give desired name to your service reference-->Click OK
It will create "ServiceReference1" under the folder "Service References" & automatically create/update app.config file
First thing take the service url address(e.g. http://youservice:808/Area.Service/Service.svc) and put it into browser url field to check whether the service is running.
In my case it wasn't running.
The remote server had a process running that used a lot or CPU and RAM (sql process)
This was blocking the service.
By closing/stopping some processes in Task Manager on remote server recovered the service.
In addition to the accepted answer, I visited the exact URL where the Service.svc mapped in URL.
From there you can see the detailed issue, on my case this is the error:
Looking at the issue, I have the correct configuration on my web.config file, but I noticed that it is looking for the assembly, from there, I figured out that I haven't reference the Service Contract project including Service Implementation and Data Access Layer assembly.
I have a WCF service operation that accepts a byte array as part of its data contract. The service is only exposed internally (not to the internet), and I want to increase the quotas to allow for a 10MB byte array.
The service is hosted in IIS7. When I try to send a byte array over the default length, I get the following exception message:
There was an error deserializing the object of type
MyService.ServiceContracts.Data. The maximum array length quota
(16384) has been exceeded while reading XML data. This quota may be
increased by changing the MaxArrayLength property on the
XmlDictionaryReaderQuotas object used when creating the XML reader.
Line 1, position 22991.
Here's the configuration:
<system.serviceModel>
<netTcpBinding>
<binding name="largeBinaryBinding" maxReceivedMessageSize="10001000"
maxBufferPoolSize="80008000" maxBufferSize="10001000"
receiveTimeout="00:01:00" openTimeout="00:01:00"
closeTimeout="00:01:00" sendTimeout="00:01:00">
<readerQuotas maxArrayLength="10000000" />
</binding>
</netTcpBinding>
<services>
<service name="MyService">
<endpoint binding="netTcpBinding"
bindingConfiguration="largeBinaryBinding"
bindingNamespace="http://my.services.co.uk/MyService"
contract="Services.MyService.ServiceContracts.IMyService" />
</service>
</services>
</system.serviceModel>
So my configuration allows for larger messages, but IIS seems to be ignoring this - how do I stop this and allow large messages through?
Again, just after I post a question I discover the answer!
When using WAS, you need to specify the full class name of the service in the configuration's service name. So in my example, I had my service implementation class called MyService, in the namespace Services. Therefore, in the configuration, I need
<service name="Services.MyService">
...
Otherwise IIS silently ignores your carefully crafted configuration! How convenient.