2013-03-01 38 views
1

嗨,大家好我使用WCF创建了一个服务,但是当我测试我的服务时,一些成功完成了为什么有些人给我下面的错误。任何关于如何解决这些问题的想法?谢谢收到我的服务的HTTP响应时WCF错误

An error occurred while receiving the HTTP response to http://localhost:8733/PortOperation/Operator_Service/ws. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details. 

Server stack trace: 
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason) 
at System.ServiceModel.Channels.HttpChannelFactory`1.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 IOperator_Service.GetAllUser(String ConnectionString) 
at Operator_ServiceClient.GetAllUser(String ConnectionString) 

Inner Exception: 
The underlying connection was closed: An unexpected error occurred on a receive. 
at System.Net.HttpWebRequest.GetResponse() 
at System.ServiceModel.Channels.HttpChannelFactory`1.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) 
+0

它看起来像在你的wcf opreation中特别的联系我想在这种方法Service.GetAllUser(String ConnectionString)exeption被抛出 – 2013-03-01 22:51:53

+0

是的,当这个方法被称为它去我的数据层获取数据,我不'不知道为什么错误,因为我的两个服务都在工作 – 2013-03-01 23:01:46

+0

您是否尝试过只使用这个测试而没有其他两个?看起来您可能会在测试中打开太多连接而未关闭它们,请参阅原始文章中的InnerException。我会试试这个,如果它工作,它本身不是代码,但可能是一次运行的测试电池,而不是关闭连接。 – 2013-03-02 02:20:50

回答

3

发生此类错误时有很多情况。

首先

检查你有没有提供适当的[DataContract]和[数据成员]是什么?如果没有提供,则会发生这种类型的错误。您必须在作为响应传递的类上方写入[DataContract],并将[DataMember]写入到进入客户端响应的类成员上方。

例如。

[DataContract] 
class Program 
{ 
    [DataMember] 
    public string Example{get;set} 
} 

检查的响应,如果数据类型的一些MINVALUE传递。这意味着某些时间数据成员在那个时候不会被初始化,而是需要minvalue。 例如int的minValue是'-2147483648',因此有时它不能被序列化并抛出错误。

如果你想跟踪这种类型的错误,然后添加以下代码在服务器端的web.config

<system.diagnostics> 
<sources> 
    <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true"> 
    <listeners> 
    <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener"  initializeData= "D:\Traces.svclog"/> 
    </listeners> 
    </source> 
</sources> 
</system.diagnostics> 

我认为这应该帮助你。

+0

这些属性不是必需的。 – sam 2016-09-13 15:28:13

2

我能解决这个问题。

如果您正在使用EF“代码优先” -approach,你想访问使用WCF数据,你应该考虑不能够使用您的 POCO类的“虚拟”的关键字,因为WCF的序列化不能序列动态延迟加载代理数据。

+0

如果您使用'AutoMapper'将域类转换为数据约定类,这是可以的。 – 2014-10-06 19:22:37