我有一个ASP.NET 4.0应用程序。
file服务使用链接源(服务实现)的.svc文件承载。web服务.svc文件位于应用程序根目录:MyApp/WebServs/mysvc.svc中的WebServs目录中。
web服务是使用Web.config (在根目录中)设置的。
<!-- Service model -->
<system.serviceModel>
<services>
<service name="DataAccessService">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="basicHttpBinding_ISRV"
contract="MyNamespace.ISRV">
</endpoint>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding_ISRV" maxReceivedMessageSize="2147483647">
<readerQuotas maxStringContentLength="1310720"
maxArrayLength="16384"
maxBytesPerRead="24096"
maxDepth="10000"
maxNameTableCharCount="16384"/>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>好的!
当我调用web服务时,我使用一个例程创建通道,以封装这个常用的逻辑:
public static ISRV GetService() {
try {
// Create the service endpoint
BasicHttpBinding bhttpb = new BasicHttpBinding(
BasicHttpSecurityMode.TransportCredentialOnly);
bhttpb.MaxReceivedMessageSize = 2147483647;
bhttpb.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas();
bhttpb.ReaderQuotas.MaxArrayLength = 16384);
bhttpb.ReaderQuotas.MaxBytesPerRead = 24096);
bhttpb.ReaderQuotas.MaxDepth = 10000);
bhttpb.ReaderQuotas.MaxNameTableCharCount = 16384);
bhttpb.ReaderQuotas.MaxStringContentLength = 1310720);
ServiceEndpoint httpEndpoint =
new ServiceEndpoint(
ContractDescription.GetContract(typeof(ISRV)),
bhttpb,
new EndpointAddress());
// Create channel factory and get proper channel for service.
ChannelFactory<ISRV> channelFactory = new ChannelFactory<ISRV>(httpEndpoint);
IDAS svc = channelFactory.CreateChannel();
return svc;
} catch (Exception e) {
throw new DASException("DAS Exception: " + e.Message);
}
}客户端调用此例程。而Web.config则用于配置服务服务器端。
当我试图使用大型消息(使用小消息都是正确的)执行服务时,我得到:
格式化程序在试图反序列化消息时抛出一个异常:试图反序列化参数http://((Namespace)):((Operation时出错。InnerException消息是“反序列化类型((类型))、App_Code.s5qoir2n、Version=0.0.0.0、Culture=neutral、PublicKeyToken=null]对象的错误。在读取XML数据时超过了最大字符串内容长度配额(8192)。在创建XML读取器时,可以通过更改XmlDictionaryReaderQuotas对象上的MaxStringContentLength属性来增加该配额。”有关更多细节,请参见InnerException。
我不明白。服务和客户端都有共同的设置,它读取缺陷值?此外,我和许多其他用户一样,遵循StackOverflow中的说明。
请帮帮我。谢谢你
发布于 2011-10-15 21:15:01
您指定了WCF4.0(确切地说,是WCF4.0),所以我想知道您遇到的问题是否是您实际上碰到了一个默认端点,除非另有重写,否则它将使用默认值进行绑定?
WCF 4.0将提供一个默认端点(设置为服务所在的位置)。该默认端点很可能使用绑定的默认值(在MaxStringContentLength的情况下为8192)。
由于您在WebServs目录(根目录)上的目录中完成了服务的所有配置,那么它可能是求助于默认端点吗?我确实意识到,Web.config文件将继承上述文件,但如果您还没有考虑到这一点,至少要考虑一下。
关于4.0的默认端点和其他更改的更多信息可以在这里找到:开发人员介绍Windows通信基金会4
https://stackoverflow.com/questions/7778699
复制相似问题