I receive this error when I try to send things to a Webservice with WP7.
The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation '
SubmitMobileData
'. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing theMaxStringContentLength
property on theXmlDictionaryReaderQuotas
object used when creating the XML reader. Line 178, position 21.
I figure its not my web service. Its actually my WP7 trying to serialize the data inside XML. Well my question is how do I set the XmlDictionaryReaderQuotas
.MaxStringContentLength
property in my WP7 app. I know how to set it on the Client of a Desktop App and inside a Webservice. But I CANT set it inside the App.XAML file of a WP7 App.
EDIT: I posted the client.config below. I decided to keep th开发者_Python百科e service address open for those wanting to see about connecting to the service. When this question is hopefully answered, I will remove the wcf connection.
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMobileUtilities" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://utopiapimp.com/services/MobileUtilities.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMobileUtilities"
contract="PimpMobileService.IMobileUtilities" name="BasicHttpBinding_IMobileUtilities" />
</client>
</system.serviceModel>
The specified exception is thrown when:
- The application hosting the web service did not specify
maxStringContentLength
reader quota (therefore the default one in used) or the quota is set too low; - Length of at least one of string arguments of invoked web method has violated
maxStringContentLength
reader quota.
As the exception states, the error happened when deserializing body of request message for operation 'SubmitMobileData'.
Usually, the serialization occurs on client side and deserialization on service side. Therefore, reader quotas of the binding used by the web service must be added (or updated) to contain the maxStringContentLength
attribute having value big enough for each SubmitMobileData
invocation to succeed.
EDIT:
Change configuration of your service's configuration to increase XML element content length limit. Do not copy this over your configuration, just merge it in:
<system.serviceModel>
<services>
<service name="Server.MobileUtilities">
<endpoint address="http://utopiapimp.com/services/MobileUtilities.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMobileUtilities"
contract="ServiceReferences.IMobileUtilities" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMobileUtilities">
<!-- Content of each XML element can be up to 10 million characters. -->
<readerQuotas maxStringContentLength="10000000" />
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
EDIT: I appears that issue is with the service after all.
If the issue was on the client side, following exception would be thrown instead of the exception you are getting:
The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader.
Since Silverlight assemblies are a subset of WP7 assemblies, reader quotas on client side are always set to max values.
This is part of XmlDictionaryReaderQuotas class definition:
static XmlDictionaryReaderQuotas()
{
maxQuota = new XmlDictionaryReaderQuotas(0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff);
}
public static XmlDictionaryReaderQuotas Max
{
get
{
return maxQuota;
}
}
So basically what you want to do is change the characteristics of your WP7 app connection right?
Before you can call the remote method you fist have to create a instance of the soapclient object and then call it's OpenAsync()
method. When you inizitialize this soapclient you can provide a System.ServiceModel.Channels.Binding()
. What if you programatically create this binding and in that set the appropriate maxStringContentLength
?
精彩评论