使用 <services> 配置 WCF标签 [英] configuring WCF with <services> tag

查看:25
本文介绍了使用 <services> 配置 WCF标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解决在我之前的问题中发现的 WCF 错误.基本上,错误是:

I am trying to solve a WCF error found in my previous question. Basically, the error is:

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

有人建议在我的 web.config 中使用 services 标签来解决我的问题.

And someone suggested to use a services tag in my web.config to resolve my issue.

现在,我面临着不同的问题.我不知道如何在我的 web.config 中配置 services 标签才能在我的服务器上正常工作.当我尝试使用 services 标签时,我总是收到以下错误:

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:

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

这是我添加了 services 标签的 web.config:

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>

请注意,删除 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.

如果我在 web.config 上做错了什么,特别是在我的 services 标签中,有人能告诉我吗?!

so could someone please tell me if I am doing something wrong on my web.config, specifically in my services tag?!

推荐答案

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

Okay, let's tackle this:

首先,您需要使用一些自定义设置定义一个自定义的basicHttpBinding 绑定配置:

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>

此部分需要在您的服务器端的 web.config 以及您的客户端的配置中.

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>

检查要点:

  • 您的服务名称必须是您的服务类的完全限定名称 (YourNamespace.YourClassName) - 实现您的服务合同的类
  • 端点中的服务合同还必须是服务合同的完全限定名称 (YourNamespace.IYourServiceContract)
  • 标记的行为配置必须引用并完全匹配 中定义的 name= 属性> 部分
  • 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.

这篇关于使用 &lt;services&gt; 配置 WCF标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆