C# WCF传输错误
我有一个WCF服务,当托管在本地计算机上时可以工作,但当托管在服务器上的IIS时不能工作 引发未处理的通信异常 。“接收对{url}的HTTP响应时出错。此 可能是由于服务端点绑定未使用HTTP 协议。这也可能是由于HTTP请求上下文 服务器已中止(可能是由于服务关闭)。请参阅 有关详细信息,请参阅服务器日志。“ 内部的例外是 “基础连接已关闭:上发生意外错误 接受。” 我已经启用了跟踪功能,但由于我的过错,我无法在那里找到任何对我有帮助的东西。另外,我也看到了关于这个问题的其他线索,但似乎没有任何帮助 服务器正在使用https,我忍不住认为这就是问题所在。当我使用http在本地运行它时。一切正常 这些调用正在检索大量数据,但我无能为力 谁能帮我一下吗 Web.ConfigC# WCF传输错误,c#,wcf,wcf-binding,C#,Wcf,Wcf Binding,我有一个WCF服务,当托管在本地计算机上时可以工作,但当托管在服务器上的IIS时不能工作 引发未处理的通信异常 。“接收对{url}的HTTP响应时出错。此 可能是由于服务端点绑定未使用HTTP 协议。这也可能是由于HTTP请求上下文 服务器已中止(可能是由于服务关闭)。请参阅 有关详细信息,请参阅服务器日志。“ 内部的例外是 “基础连接已关闭:上发生意外错误 接受。” 我已经启用了跟踪功能,但由于我的过错,我无法在那里找到任何对我有帮助的东西。另外,我也看到了关于这个问题的其他线索,但似乎没有
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" maxRequestLength="2147483647" executionTimeout="2147483647"/>
</system.web>
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="false" logMessagesAtServiceLevel="false" logMessagesAtTransportLevel="true" maxMessagesToLog="3000" maxSizeOfMessageToLog="2000"></messageLogging>
</diagnostics>
<services>
<service name="Logistics.Wcf.LogisticsService" behaviorConfiguration="serviceBehavior" >
<endpoint address="soap" binding="basicHttpsBinding" contract="Logistics.Wcf.ILogisticsService"></endpoint>
<!--<endpoint address="rest" binding="webHttpBinding" contract="Logistics.Wcf.ILogisticsService" behaviorConfiguration="restBehavior"></endpoint>-->
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="restBehavior">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpsBinding>
<binding name="basicHttpsBinding"
closeTimeout="00:15:00"
openTimeout="00:15:00"
receiveTimeout="00:15:00"
sendTimeout="00:15:00"
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
>
<security>
<transport clientCredentialType="None"></transport>
</security>
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</basicHttpsBinding>
</bindings>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<validation validateIntegratedModeConfiguration="false" />
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
<connectionStrings>
<add name="LogisticsEntities" connectionString="metadata=res://*/LogisticsModel.csdl|res://*/LogisticsModel.ssdl|res://*/LogisticsModel.msl;provider=System.Data.SqlClient;provider connection string="data source=hertz1105\devl;initial catalog=Logistics;user id=airclic2;password=air123_***;connect timeout=6000;applicationintent=ReadWrite;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing">
<listeners>
<add name="log" type="System.Diagnostics.XmlWriterTraceListener" initializeData="Traces.scvlog"></add>
</listeners>
</source>
</sources>
<trace autoflush="true"></trace>
</system.diagnostics>
合同:
[OperationContract]
[WebGet(UriTemplate = "/GetDeliveryInstructions?authenticationToken={AUTHENTICATIONTOKEN}&countryCode={COUNTRYCODE}&beginDate={BEGINDATE}&endDate={ENDDATE}", ResponseFormat = WebMessageFormat.Xml)]
List<DeliveryInstruction> GetDeliveryInstructions(string authenticationToken, string countryCode, string beginDate, string endDate);
[运营合同]
[WebGet(UriTemplate=“/GetDeliveryInstructions?authenticationToken={authenticationToken}&countryCode={countryCode}&beginDate={beginDate}&endDate={endDate}”,ResponseFormat=WebMessageFormat.Xml)]
列出GetDeliveryInstructions(字符串authenticationToken、字符串countryCode、字符串beginDate、字符串endDate);
服务方式:
public List<DeliveryInstruction> GetDeliveryInstructions(string authenticationToken, string countryCode, string beginDate, string endDate)
{
try
{
if (AuthenticationTokenValidator.IsValidToken(authenticationToken))
return DeliveryInstructionAdministrator.GetList(countryCode, beginDate, endDate).ToList();
else
throw new InvalidOperationException("Your token is invalid or expired.");
}
catch (FaultException<TimeoutException>)
{
return DeliveryInstructionAdministrator.GetList(countryCode, beginDate, endDate).ToList();
}
catch (FaultException faultException)
{
WebServiceExceptionLog logEntry = new WebServiceExceptionLog(faultException, "Logistics.Wcf", "GetDeliveryIntructions", faultException.GetType().ToString(), authenticationToken);
ExceptionLogger.LogException(logEntry);
return null;
}
catch (CommunicationException communcationException)
{
WebServiceExceptionLog logEntry = new WebServiceExceptionLog(communcationException, "Logistics.Wcf", "GetDeliveryIntructions", communcationException.GetType().ToString(), authenticationToken);
ExceptionLogger.LogException(logEntry);
return null;
}
}
public List GetDeliveryInstructions(字符串authenticationToken、字符串countryCode、字符串beginDate、字符串endDate)
{
尝试
{
if(AuthenticationTokenValidator.IsValidToken(authenticationToken))
return DeliveryInstructionAdministrator.GetList(countryCode、beginDate、endDate).ToList();
其他的
抛出新的InvalidOperationException(“您的令牌无效或过期”);
}
捕获(错误异常)
{
return DeliveryInstructionAdministrator.GetList(countryCode、beginDate、endDate).ToList();
}
捕获(FaultException FaultException)
{
WebServiceExceptionLogEntry=新的WebServiceExceptionLog(faultException,“Logistics.Wcf”,“GetDeliveryIntructions”,faultException.GetType().ToString(),authenticationToken);
异常日志记录器。日志异常(日志条目);
返回null;
}
捕获(通信异常通信异常)
{
WebServiceExceptionLogEntry=新的WebServiceExceptionLog(CommunicationException,“Logistics.Wcf”,“GetDeliveryIntructions”,CommunicationException.GetType().ToString(),authenticationToken);
异常日志记录器。日志异常(日志条目);
返回null;
}
}
*更新*
问题在于实体框架。我正在使用实体框架检索POCO实体。但仍然不确定如何修复它 您应该在服务器上启用wcf日志记录。但是,当maxRequestLength在web.config和传入消息中设置不正确时,我看到了此错误,其中大:
<system.web>
<httpRuntime maxRequestLength="10000" />
</system.web>
启用跟踪:
<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>
</configuration>
我在wcf跟踪侦听器设置中没有看到错误。这可能会给你带来更多的启示。这可能是一个愚蠢的问题;但是你有没有检查过事件日志,看看那里发生了什么?您有时会在那里看到在实际应用程序中得到的异常中没有看到的信息。此外,请检查在服务器托管时是否可以通过HTTP访问服务,这将排除这是纯粹的IIS问题还是服务器问题,以及通过HTTPS端口443访问的更多问题。也;再次检查服务器上的服务是否有HTTPS绑定。我确实在服务器上启用了跟踪。