使用标记配置WCF
|
我试图解决WCF错误
found in my previous question.基本上,错误是:
读取XML数据时已超出最大字符串内容长度配额(8192). 有人建议在我的web.config中使用服务标签来解决我的问题. 现在,我面临着一个不同的问题.我无法弄清楚我怎么想在我的web.config中配置服务标签才能在我的服务器上正常工作.当我尝试使用services标记时,我总是收到以下错误: 服务器没有提供有意义的回复;这可能是由合同不匹配,过早的会话关闭或内部服务器错误引起的. 这是我添加了services标签的web.config: <system.serviceModel>
<bindings>
<basicHttpBinding>
<binding
name="BasicHttpBinding_Service1"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
allowCookies="false"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536"
maxBufferPoolSize="524288"
maxReceivedMessageSize="65536"
messageEncoding="Text"
textEncoding="utf-8"
transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas
maxDepth="32"
maxStringContentLength="10000"
maxArrayLength="16384"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint
address="http://localhost:53931/WCF/Service1.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_Service1"
contract="ServiceReference.Service1"
name="BasicHttpBinding_Service1" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<!--PROBLEM SOMEWHERE IN THE SERVICES TAG-->
<services>
<service
behaviorConfiguration="NewBehavior"
name="AspPersonalWebsite.ServiceReference">
<endpoint
address="http://localhost:53931/WCF/Service1.svc"
binding="basicHttpBinding"
contract="ServiceReference.Service1"
bindingConfiguration="BasicHttpBinding_Service1" />
</service>
</services>
请注意,通过删除服务标签一切正常,但我将无法解决我在previous question上发布的原始问题. 那么有人可以告诉我,如果我在web.config上做错了什么,特别是在我的服务标签中?! 解决方法
好的,我们来解决这个问题:
首先,您需要使用一些自定义设置定义自定义basicHttpBinding绑定配置: <bindings>
<basicHttpBinding>
<binding name="LargeSettings"
maxBufferSize="524288"
maxBufferPoolSize="524288"
maxReceivedMessageSize="6553600">
<readerQuotas maxDepth="32" maxStringContentLength="100000"
maxArrayLength="16384" maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
此部分需要位于服务器端的web.config以及客户端的配置中. 其次,在服务器端,您需要一个< services>用于定义服务及其端点及其配置的标记: <services>
<service name="YourNamespace.YourClassName"
behaviorConfiguration="ServiceWithMetadata">
<endpoint name="Default"
address="http://localhost:53931/WCF/Service1.svc"
binding="basicHttpBinding"
bindingConfiguration="LargeSettings"
contract="YourNamespace.IServiceContract" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceWithMetadata">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
要点检查: >您的服务名称必须是服务类的完全限定名称(YourNamespace.YourClassName) – 实现服务合同的类 第三,在客户端,你需要这样的东西: <client>
<endpoint name="Default"
address="http://localhost:53931/WCF/Service1.svc"
binding="basicHttpBinding"
bindingConfiguration="LargeSettings"
contract="ServiceReference.IYourService" />
</client>
您需要在服务器端引用服务定义中定义的端点,您需要使用相同的绑定和绑定配置,并且需要使用服务引用中定义的服务合同. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
