使用配置 WCF标签

发布于 2024-10-12 09:51:26 字数 2836 浏览 3 评论 0原文

我正在尝试解决在上一个问题中发现的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

止于盛夏 2024-10-19 09:51:27

好的,让我们解决这个问题:

首先,您需要使用一些自定义设置定义自定义 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>
   <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) - 实现您的服务合同的类
  • 您的服务合同端点中的 还必须是服务合同的完全限定名称 (YourNamespace.IYourServiceContract),
  • 标记的behaviorConfiguration 必须引用并匹配完全符合 部分中定义的 name= 属性

第三,在客户端,您需要这样的东西:

<client>
  <endpoint name="Default"
            address="http://localhost:53931/WCF/Service1.svc"
            binding="basicHttpBinding"
            bindingConfiguration="LargeSettings"
            contract="ServiceReference.IYourService" />
</client>

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

Okay, let's tackle this:

First, you need to define a custom basicHttpBinding binding configuration with some custom settings:

<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>

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:

<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>

Points to check:

  • your service name must be the fully qualified name (YourNamespace.YourClassName) of your service class - the class that implements your service contract
  • your service contract in the endpoint must also be the fully qualified name of your service contract (YourNamespace.IYourServiceContract)
  • the behaviorConfiguration of your <service> tag must reference and match exactly to the name= attribute as defined in your <behaviors> section

And thirdly, on the client side, you need something like this:

<client>
  <endpoint name="Default"
            address="http://localhost:53931/WCF/Service1.svc"
            binding="basicHttpBinding"
            bindingConfiguration="LargeSettings"
            contract="ServiceReference.IYourService" />
</client>

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.

我要还你自由 2024-10-19 09:51:27

对于使用内置服务引用的用户,只需使用 .Endpoint.Binding =THE NEW BINDING

ex:

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;

For those using the built in service reference, just use the .Endpoint.Binding =THE NEW BINDING

ex:

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;
盗琴音 2024-10-19 09:51:27

将此设置用于您的绑定,

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

Use this setting for the your bindings,

 <basicHttpBinding>
        <binding maxReceivedMessageSize="2147483647"  messageEncoding="Text" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" >
          <readerQuotas  maxStringContentLength="525288"></readerQuotas>
        </binding>
      </basicHttpBinding>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文