使用配置 WCF标签
我正在尝试解决在上一个问题中发现的 WCF 错误。基本上,错误是:
读取 XML 数据时超出了最大字符串内容长度配额 (8192)。
有人建议在我的 web.config 中使用 services 标记解决我的问题。
现在,我面临着一个不同的问题。我不知道如何配置 web.config 中的 services 标记才能在我的服务器上正常工作。当我尝试使用服务标签时,我总是收到以下错误:
服务器没有提供有意义的回复;这可能是由合同不匹配、会话过早关闭或内部服务器错误引起的。
这是我的 web.config,添加了 services 标签:
<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>
请注意,通过删除 >services 标签一切正常,但随后我将无法解决我的 上一个问题。
那么有人可以告诉我我的 web.config 上是否做错了什么,特别是在我的 services 标签中?!
I am trying to solve a WCF error found in my previous question. Basically, the error is:
The maximum string content length quota (8192) has been exceeded while reading XML data.
And someone suggested to use a services tag in my web.config to resolve my issue.
Now, I am facing a different problem. I can’t figure out how am I suppose to configure the services tag in my web.config to work correctly on my server. I always get the following error when I try to use the services tag:
The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
Here is my web.config with the services tag added:
<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>
Please note that by removing the services tag everything works fine, but then I will not be able to resolve my original problem posted on my previous question.
so could someone please tell me if I am doing something wrong on my web.config, specifically in my services tag?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的,让我们解决这个问题:
首先,您需要使用一些自定义设置定义自定义
basicHttpBinding
绑定配置:此部分需要位于您的服务器端web.config,以及您的客户端配置。
其次,在服务器端,您需要有一个
标记来定义您的服务及其端点及其配置:检查要点:
YourNamespace.YourClassName
) - 实现您的服务合同的类YourNamespace.IYourServiceContract
),
标记的behaviorConfiguration 必须引用并匹配完全符合
部分中定义的name=
属性第三,在客户端,您需要这样的东西:
您需要在服务器端引用服务定义中定义的端点,需要使用相同的绑定和绑定配置,并且需要使用服务引用中定义的服务契约。
Okay, let's tackle this:
First, you need to define a custom
basicHttpBinding
binding configuration with some custom settings:This section needs to be in both your server-side's web.config, as well as your client side's config.
Secondly, on the server-side, you need to have a
<services>
tag that defines your service and its endpoints and their configuration:Points to check:
YourNamespace.YourClassName
) of your service class - the class that implements your service contractYourNamespace.IYourServiceContract
)<service>
tag must reference and match exactly to thename=
attribute as defined in your<behaviors>
sectionAnd thirdly, on the client side, you need something like this:
You need to reference the endpoint defined in your service's definition on the server side, you need to use the same binding and binding configuration, and you need to use the service contract as defined in your service reference.
对于使用内置服务引用的用户,只需使用
.Endpoint.Binding =THE NEW BINDING
ex:
For those using the built in service reference, just use the
.Endpoint.Binding =THE NEW BINDING
ex:
将此设置用于您的绑定,
Use this setting for the your bindings,