任何人都可以指导我进行 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>