【发布时间】:2014-03-25 13:56:45
【问题描述】:
在 IIS 8.0 中托管的 wcf 应用程序 (.NET FW 4.0) 中,我想发送一个带有两个大字符串的复杂 DataMember 作为参数。这些字符串可以达到 20 或更多 MB。一开始我用了transferMode=Streamed,但是总是报错:
附加信息:格式化程序在尝试反序列化消息时抛出异常:尝试反序列化时出现错误 反序列化参数http://tempuri.org/:request。内部异常 消息是“反序列化类型对象时出错 QCheckerService.Parameter。最大字符串内容长度配额 (8192) 在读取 XML 数据时已超出。这个配额可能是 通过更改 MaxStringContentLength 属性增加 创建 XML 阅读器时使用的 XmlDictionaryReaderQuotas 对象。
我在配置文件中将 readerQuotas all 设置为 max。但错误与 XmlDictionaryReaderQuotas 有关。有没有办法避免在代码中更改这些后面的配额?
我现在有点困惑,什么是合适的解决方案。默认的 transferMode=Buffered 是正确的方法吗?
或者大字符串的传输是不可能的,我应该使用其他方式?
如果我传输小字符串,它会起作用。这里是附加配置。
客户端 app.config:
<system.serviceModel>
<client>
<endpoint address=http://localhost:12412/Service1.svc
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IQChecker"
contract="QCheckerService.IQChecker">
</client>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IQChecker"
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
transferMode="Streamed">
<readerQuotas maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
服务 web.config:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="Basic"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
transferMode="Streamed">
<readerQuotas maxBytesPerRead="2147483647"
maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
相关DataMember的服务接口
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "MyMethod", BodyStyle = WebMessageBodyStyle.Bare)]
ReturnValue MyMethod (Parameter request);
[DataContract]
public class Parameter: IDisposable
{
[DataMember]
String String1;
[DataMember]
String String2;
public void SetString1(String drawing)
{
String1 = drawing;
}
public String GetString1()
{
return String1;
}
public void SetString2(String configuration)
{
String2 = configuration;
}
public String GetString2()
{
return String2;
}
public void Dispose()
{
}
感谢您的建议。
【问题讨论】:
-
如果你想要一个正确的答案,包括你的相关 web.config 设置和至少一个方法签名。
-
问题可能出在客户端配置中,因此请同时包含客户端配置文件。
-
异常消息似乎准确地说明了问题所在。
-
您的服务器配置中没有定义端点?
-
不,对于本地主机它没有工作。