2

任何人都可以指导我进行 WCF 配置,我收到错误(400) 错误请求和跟踪查看器告诉我:

“已超出传入消息 (65536) 的最大消息大小配额。要增加配额,请在适当的绑定元素上使用 MaxReceivedMessageSize 属性。”

我查看了客户端的 app.config 并相应地更改了属性,但问题仍然存在,然后我查看了服务器的 web.config,发现根本没有<service>...</service>标签,所以我右键单击web.config并选择Edit WCF configuration了一个弹出窗口并单击了几下,我的 wcf 服务配置已准备就绪,但它开始抛出

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

跟踪查看器显示 3 个警告:

“无法打开 System.ServiceModel.ServiceHost”

“故障 System.ServiceModel.ServiceHost”

“服务主机故障”

这是我的服务器 web.configs:

版本 0(工作但有限制):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
        <listeners>
          <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\log\Traces1.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
  <connectionStrings>
    <add name="PopulizerConnectionString" connectionString="Data Source=VM-LU4\SQLSERVER;Initial Catalog=Populizer;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
</configuration>

还有一个显示 3 个警告:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
        <listeners>
          <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\log\Traces1.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
  <connectionStrings>
    <add name="PopulizerConnectionString" connectionString="Data Source=VM-LU4\SQLSERVER;Initial Catalog=Populizer;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="NewServiceType">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:1948/Commander.svc" />
          </baseAddresses>
        </host>
      </service>
      <service name="Populator.Commander">
        <endpoint address="http://localhost:1948/Commander.svc" binding="basicHttpBinding"
          bindingConfiguration="" name="CommanderEndpoint" contract="Private.ICommander" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
</configuration>

编辑

这是我的网络配置的第 3 版,在 TraceViewer 中仍然显示相同的三个警告

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
        <listeners>
          <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\log\Traces.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
  <connectionStrings>
    <add name="PopulizerConnectionString" connectionString="Data Source=VM-LU4\SQLSERVER;Initial Catalog=Populizer;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="httpBasicBinding_Service01" closeTimeout="00:10:00"
          openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
          maxBufferSize="655360000"
          maxBufferPoolSize="655360000" maxReceivedMessageSize="655360000">
          <readerQuotas maxDepth="655360000" maxStringContentLength="655360000"
            maxArrayLength="655360000" maxBytesPerRead="655360000" maxNameTableCharCount="655360000" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="NewServiceType">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:1948/Commander.svc" />
          </baseAddresses>
        </host>
      </service>
      <service name="Populator.Commander">
        <endpoint address="http://localhost:1948/Commander.svc" binding="basicHttpBinding"
          bindingConfiguration="httpBasicBinding_Service01" name="CommanderEndpoint" contract="Private.ICommander" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
</configuration>
4

3 回答 3

0

服务器配置中绑定元素的最大报价是多少?请查看下面的示例。

<wsHttpBinding>
    <binding name="WSHttpBinding_ISomeService" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
      textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
        enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true"
          algorithmSuite="Default" establishSecurityContext="true" />
      </security>
    </binding>
  </wsHttpBinding>
于 2011-06-24T16:46:55.883 回答
0

您需要设置绑定配置。

你写的地方:

bindingConfiguration = ""

你应该写:

bindingConfiguration="httpBasicBinding_Service01"

然后配置:

<basicHttpBinding>
    <binding name="httpBasicBindingService 01" closeTimeout="00:10:00"
      openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
      maxBufferSize="655360000"
      maxBufferPoolSize="655360000" maxReceivedMessageSize="655360000">
      <readerQuotas maxDepth="655360000" maxStringContentLength="655360000"
        maxArrayLength="655360000" maxBytesPerRead="655360000" maxNameTableCharCount="655360000" />
    </binding>
  </basicHttpBinding>
于 2011-06-24T16:48:00.967 回答
0

从工作到配置的非工作版本的逐步配置有所帮助。这是服务器的 web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
        <listeners>
          <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\log\Traces.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
  <connectionStrings>
    <add name="PopulizerConnectionString" connectionString="Data Source=VM-LU4\SQLSERVER;Initial Catalog=Populizer;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding  name="ICommander_BindingConfiguration"
                  closeTimeout="01:00:00"
                  openTimeout="00:01:00"
                  receiveTimeout="00:10:00"
                  sendTimeout="00:01:00"
                  allowCookies="false"
                  bypassProxyOnLocal="false"
                  hostNameComparisonMode="StrongWildcard"
                  maxBufferSize="1048576"
                  maxBufferPoolSize="524288"
                  maxReceivedMessageSize="1048576"
                  messageEncoding="Text"
                  textEncoding="utf-8"
                  transferMode="Buffered"
                  useDefaultWebProxy="true"
        >
          <readerQuotas
              maxDepth="32"
              maxStringContentLength="1048576"
              maxArrayLength="1048576"
              maxBytesPerRead="4096"
              maxNameTableCharCount="1048576"
          />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
        <binding
          name="ICommunicator_BindingConfiguration"
          closeTimeout="01:00:00"
          openTimeout="00:01:00"
          receiveTimeout="00:10:00"
          sendTimeout="00:01:00"
          allowCookies="false"
          bypassProxyOnLocal="false"
          hostNameComparisonMode="StrongWildcard"
          maxBufferSize="1048576"
          maxBufferPoolSize="524288"
          maxReceivedMessageSize="1048576"
          messageEncoding="Text"
          textEncoding="utf-8"
          transferMode="Buffered"
          useDefaultWebProxy="true"
        >
          <readerQuotas
              maxDepth="32"
              maxStringContentLength="1048576"
              maxArrayLength="1048576"
              maxBytesPerRead="4096"
              maxNameTableCharCount="1048576"
          />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="Populator.Commander">
        <endpoint contract="Private.ICommander" binding="basicHttpBinding" bindingConfiguration="ICommander_BindingConfiguration" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="CommanderBehavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
</configuration>
于 2011-06-27T16:22:38.133 回答