WP7:WebService 调用中序列化字符串时出错
当我尝试使用 WP7 将内容发送到 Web 服务时,我收到此错误。
格式化程序在尝试反序列化消息时引发异常:反序列化操作“
SubmitMobileData
”的请求消息正文时出错。读取 XML 数据时超出了最大字符串内容长度配额 (8192)。通过更改创建 XML 读取器时使用的XmlDictionaryReaderQuotas
对象的MaxStringContentLength
属性,可以增加此配额。第 178 行,位置 21。
我认为这不是我的网络服务。它实际上是我的 WP7 试图序列化 XML 中的数据。我的问题是如何在 WP7 应用程序中设置 XmlDictionaryReaderQuotas
.MaxStringContentLength
属性。我知道如何在桌面应用程序的客户端和 Web 服务内部设置它。但我无法将其设置在 WP7 应用程序的 App.XAML 文件中。
编辑:我在下面发布了 client.config。我决定为那些想要查看连接到该服务的人保留该服务地址。当这个问题有希望得到解答时,我将删除 wcf 连接。
<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>
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 the 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在以下情况下会引发指定的异常:
maxStringContentLength
读取器配额(因此使用默认值)或配额设置得太低;maxStringContentLength
读取器配额。正如异常所示,在反序列化操作“SubmitMobileData”的请求消息正文时发生错误。
通常,序列化发生在客户端,反序列化发生在服务端。因此,必须添加(或更新)Web 服务使用的绑定的读取器配额,以包含具有足够大值的
maxStringContentLength
属性,以便每次SubmitMobileData
调用成功。编辑:
更改服务配置以增加 XML 元素内容长度限制。不要将其复制到您的配置中,只需将其合并到:
编辑:
我看来问题毕竟出在服务上。
如果问题出现在客户端,则会引发以下异常,而不是您收到的异常:
由于 Silverlight 程序集是 WP7 程序集的子集,因此客户端的读取器配额始终设置为最大值。
这是 XmlDictionaryReaderQuotas 类定义的一部分:
The specified exception is thrown when:
maxStringContentLength
reader quota (therefore the default one in used) or the quota is set too low;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 eachSubmitMobileData
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:
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:
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:
所以基本上您想要做的是更改 WP7 应用程序连接的特征,对吗?
在调用远程方法之前,您首先必须创建soapclient 对象的实例,然后调用它的
OpenAsync()
方法。当您初始化此soapclient时,您可以提供System.ServiceModel.Channels.Binding()
。如果您以编程方式创建此绑定并在其中设置适当的 maxStringContentLength 会怎样?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 aSystem.ServiceModel.Channels.Binding()
. What if you programatically create this binding and in that set the appropriatemaxStringContentLength
?