.net 使用WCF服务时出现奇怪的异常(可能是字符编码异常?)
我正在调用我以前创建的一个WCF服务,该服务查询语义数据库并返回dbpedia.org链接,这些链接包含实体的名称,例如,您可以找到“http://dbpedia.org/resource/Barack_Obama“或”http://dbpedia.org/resource/Brazil" 我面临的问题是,在调用返回前面提到的URI的方法时,该方法大部分时间都有效,但很少发生此错误: 基础连接已关闭:服务器已关闭预期保持活动状态的连接.net 使用WCF服务时出现奇怪的异常(可能是字符编码异常?),.net,wcf,http,character-encoding,windows-services,.net,Wcf,Http,Character Encoding,Windows Services,我正在调用我以前创建的一个WCF服务,该服务查询语义数据库并返回dbpedia.org链接,这些链接包含实体的名称,例如,您可以找到“http://dbpedia.org/resource/Barack_Obama“或”http://dbpedia.org/resource/Brazil" 我面临的问题是,在调用返回前面提到的URI的方法时,该方法大部分时间都有效,但很少发生此错误: 基础连接已关闭:服务器已关闭预期保持活动状态的连接 Server stack trace: at Sys
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)
at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at ComparisonServiceInterface.Compare(String[] URIs)
at ComparisonServiceInterfaceClient.Compare(String[] URIs)
Inner Exception:
The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
Inner Exception:
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
Inner Exception:
An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
我想可能有些资源有不同的编码,比如“http://dbpedia.org/resource/Sergio_Ag也许是“你”这个角色的“你”吧
我尝试在发送回uri之前对其进行编码,但它仍会引发相同的异常
服务配置文件如下所示:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<system.serviceModel>
<services>
<service name="mergedServices.MergedService">
<endpoint address="" binding="wsHttpBinding" contract="mergedServices.RelationGeneratorServiceInterface">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="" binding="wsHttpBinding" contract="mergedServices.keywordSearchServiceInterface">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="" binding="wsHttpBinding" contract="mergedServices.QAServiceInterface">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="" binding="wsHttpBinding" contract="mergedServices.CompareWithOnePredicateServiceInterface">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="" binding="wsHttpBinding" contract="mergedServices.ComparisonServiceInterface">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="" binding="wsHttpBinding" contract="mergedServices.ProfileConstructorInterface">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/mergedServices/" />
</baseAddresses>
</host>
</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="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
在故障中临时包含异常详细信息,这将允许您获得真正的错误。此外,在服务中重新引用异常之前,您应该记录异常,这样您就可以知道真正的问题是什么,而不必在故障中包含异常详细信息
<serviceDebug includeExceptionDetailInFaults="True"/>
您是否在每次请求后关闭香奈儿?不清楚问题是您在使用特殊字符(“)时总是出现此错误,还是您只是偶尔出现此错误,并猜测可能是特殊字符。服务器端没有发生异常,异常发生在传输中