使用<;配置WCF;服务>;标签

使用<;配置WCF;服务>;标签,wcf,web-config,Wcf,Web Config,我正在尝试解决一个WCF错误。基本上,错误是: 读取XML数据时已超过最大字符串内容长度配额(8192)。 有人建议在我的web.config中使用服务标记来解决我的问题 现在,我面临着一个不同的问题。我不知道如何在我的web.config中配置服务标记以在我的服务器上正常工作。当我尝试使用服务标记时,总是会出现以下错误: 服务器没有提供有意义的回复;这可能是由于契约不匹配、会话过早关闭或内部服务器错误造成的。 这是我的web.config,添加了服务标记: <system.service

我正在尝试解决一个WCF错误。基本上,错误是:

读取XML数据时已超过最大字符串内容长度配额(8192)。

有人建议在我的web.config中使用服务标记来解决我的问题

现在,我面临着一个不同的问题。我不知道如何在我的web.config中配置服务标记以在我的服务器上正常工作。当我尝试使用服务标记时,总是会出现以下错误:

服务器没有提供有意义的回复;这可能是由于契约不匹配、会话过早关闭或内部服务器错误造成的。

这是我的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>

请注意,通过删除服务标签,一切正常,但这样我就无法解决我在网站上发布的原始问题


有人能告诉我我的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>

您需要在服务器端引用服务定义中定义的端点,需要使用相同的绑定和绑定配置,并且需要使用服务引用中定义的服务契约。

对于使用内置服务引用的用户,只需使用
.Endpoint.Binding=新绑定

例:


对绑定使用此设置

 <basicHttpBinding>
        <binding maxReceivedMessageSize="2147483647"  messageEncoding="Text" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" >
          <readerQuotas  maxStringContentLength="525288"></readerQuotas>
        </binding>
      </basicHttpBinding>


问题是:这真的是您在这里配置的服务吗??我指的是服务的服务器端,服务代码存在和执行的地方??您已经回答了我关于服务标签的特殊问题。但是,我仍然收到:读取XML数据时已超过最大字符串内容长度配额(8192)通过在internet场景中使用这些绑定,您将使您的服务受到DOS攻击。您在这里的基本意思是,您允许最大为2GB的传入请求!想象一下,如果黑客向您的服务发送10个2GB的请求,会发生什么。WCF将尝试在内存中分配一个2GB的缓冲区来存储每个请求,并且可能会失败。在多次tose失败后,您的应用程序池可能会终止,您的服务将不再可用。。。
<client>
  <endpoint name="Default"
            address="http://localhost:53931/WCF/Service1.svc"
            binding="basicHttpBinding"
            bindingConfiguration="LargeSettings"
            contract="ServiceReference.IYourService" />
</client>
BasicHttpBinding b = new BasicHttpBinding();
b.Security.Mode = BasicHttpSecurityMode.Transport;
...
b.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;               

MyWebServiceReference.ServiceReferenceSoapClient objRE = new MyWebServiceReference.ServiceReferenceSoapClient("ServiceReferenceSoap", "URI");
objRE.Endpoint.Binding = b;
 <basicHttpBinding>
        <binding maxReceivedMessageSize="2147483647"  messageEncoding="Text" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" >
          <readerQuotas  maxStringContentLength="525288"></readerQuotas>
        </binding>
      </basicHttpBinding>