WP7:WebService 调用中序列化字符串时出错

发布于 2024-10-18 21:05:46 字数 1388 浏览 1 评论 0原文

当我尝试使用 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 the MaxStringContentLength property on the XmlDictionaryReaderQuotas 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抱着落日 2024-10-25 21:05:46

在以下情况下会引发指定的异常:

  1. 托管 Web 服务的应用程序未指定 maxStringContentLength 读取器配额(因此使用默认值)或配额设置得太低;
  2. 调用的 Web 方法的至少一个字符串参数的长度违反了 maxStringContentLength 读取器配额。

正如异常所示,在反序列化操作“SubmitMobileData”的请求消息正文时发生错误。

通常,序列化发生在客户端,反序列化发生在服务端。因此,必须添加(或更新)Web 服务使用的绑定的读取器配额,以包含具有足够大值的 maxStringContentLength 属性,以便每次 SubmitMobileData 调用成功。

编辑

更改服务配置以增加 XML 元素内容长度限制。不要将其复制到您的配置中,只需将其合并到:

<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>

编辑
我看来问题毕竟出在服务上。

如果问题出现在客户端,则会引发以下异常,而不是您收到的异常:

读取 XML 数据时超出了最大字符串内容长度配额 (8192)。通过更改创建 XML 读取器时使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLength 属性,可以增加此配额。

由于 Silverlight 程序集是 WP7 程序集的子集,因此客户端的读取器配额始终设置为最大值。

这是 XmlDictionaryReaderQuotas 类定义的一部分:

static XmlDictionaryReaderQuotas()
{
    maxQuota = new XmlDictionaryReaderQuotas(0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff);
}

public static XmlDictionaryReaderQuotas Max
{
    get
    {
        return maxQuota;
    }
}

The specified exception is thrown when:

  1. 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;
  2. 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;
    }
}
转身泪倾城 2024-10-25 21:05:46

所以基本上您想要做的是更改 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 a System.ServiceModel.Channels.Binding(). What if you programatically create this binding and in that set the appropriate maxStringContentLength?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文