WCF传输错误
本文关键字:传输错误 WCF | 更新日期: 2023-09-27 18:18:50
我有一个WCF服务,在我的本地机器上托管时可以工作,但在服务器上托管IIS时不能工作。
抛出未处理的通信异常
。"在接收对{url}的HTTP响应时发生错误。这可能是由于服务端点绑定没有使用HTTP协议。这也可能是由于HTTP请求上下文被服务器终止(可能是由于服务关闭)。看到有关服务器日志的详细信息。"
内部异常
"底层连接已关闭:发生意外错误接收。"
我已经启用了跟踪,但由于我的错误,我找不到任何我能看到的对我有帮助的东西。此外,我也浏览了关于这个问题的其他帖子,但似乎没有任何帮助。
服务器正在使用https,我不禁认为这是问题所在。当我在本地运行它使用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);
服务方法: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;
}
}
* UPDATE *问题在于实体框架。我使用实体框架来检索POCO实体。仍然不知道如何解决它。
您应该在服务器上启用wcf日志。然而,当maxRequestLength在web中没有正确设置时,我看到了这个错误。配置和传入消息的大小:
<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