Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 接收对我的服务的HTTP响应时发生WCF错误_C#_.net_Wcf_Web Services_Wcf Binding - Fatal编程技术网

C# 接收对我的服务的HTTP响应时发生WCF错误

C# 接收对我的服务的HTTP响应时发生WCF错误,c#,.net,wcf,web-services,wcf-binding,C#,.net,Wcf,Web Services,Wcf Binding,大家好,我使用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 pr

大家好,我使用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)

出现这种错误的情况有很多种

首先

检查您是否提供了正确的[DataContract]和[DataMember]?如果未提供,则会发生此类错误。您必须在响应中传递的类上方写入[DataContract],并在进入客户机响应的类成员上方写入[DataMember]

例如

第二

如果传递了数据类型的某个minvalue,请检入响应。这意味着某个时间数据成员在获取minvalue时未初始化。 e、 g.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>

我想这会对您有所帮助。

发生这种错误的情况很多

首先

检查您是否提供了正确的[DataContract]和[DataMember]?如果未提供,则会发生此类错误。您必须在响应中传递的类上方写入[DataContract],并在进入客户机响应的类成员上方写入[DataMember]

例如

第二

如果传递了数据类型的某个minvalue,请检入响应。这意味着某个时间数据成员在获取minvalue时未初始化。 e、 g.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>

我想这会对你有帮助。

我能解决这个问题


如果使用EF代码第一种方法,并且希望使用WCF访问数据,则应考虑在POCO类中使用虚拟关键字不启用延迟加载,因为WCF序列化不能序列化动态代理数据。

< P>我能够解决这个问题。

如果使用EF代码第一种方法,并且希望使用WCF访问数据,则应考虑不使用PoCO类中的虚拟关键字来启用延迟加载,因为WCF序列化不能序列化动态代理数据。Service.GetAllUserString ConnectionString exeption是thrownYes,当调用该方法时,它将转到我的数据层以获取数据,我不知道为什么会出现错误,因为我的两个服务正在工作。您是否尝试只运行此测试而不运行其他两个测试?看起来您可能在测试中打开了太多连接而没有关闭它们,请参阅原始文章中的InnerException。我会尝试这个方法,如果它有效,它不是代码本身,但可能是一组测试同时运行,而不是关闭连接。它看起来像是在您的wcf操作联系人中,特别是我认为在这个方法服务中。GetAllUserString ConnectionString exeption是thrownYes,当调用该方法时,它会转到我的数据层获取数据,我不知道为什么会出现错误,因为我的两个服务正在工作。您是否尝试只运行此测试而不运行其他两个测试?看起来您可能在测试中打开了太多连接而没有关闭它们,请参阅原始文章中的InnerException。我会尝试这个方法,如果它有效,它不是代码本身,但可能是一组测试同时运行,而不是关闭连接。如果您使用AutoMapper将域类转换为数据协定类,这是可以的。但是,如果您使用AutoMapper将域类转换为数据协定类,这是可以的。