2011-05-03 51 views
0

我有这个很奇怪的错误...WCF错误 - 连接被远程主机关闭

我正在开发一个WCF服务,我从其他人那里接管了。有这样定义的类称为用户:

namespace WebApi.DataContracts 
{ 
    [DataContract] 
    public class User 
    { 
     [DataMember] 
     public int Id 
     { 
      get; 
      set; 
     } 
     [DataMember] 
     public string Username 
     { 
      set; 
      get; 
     } 
    ... 
     [DataMember] 
     public DateTime Birth 
     { 
      get; 
      set; 
     } 
     [DataMember] 
     public bool Newsletter 
     { 
      get; 
      set; 
     } 

等等

我做了一个API方法,返回此对象作为数据

namespace WebApi 
{ 
    public class SoapApi : IApi 
    { 
     public DataContracts.User UserRegister() 
     { 
      DataContracts.User u = new DataContracts.User(); 
      return u; 
    } 
} 

当我尝试从客户端调用这个,我得到这个错误:

[SocketException (0x2746): An existing connection was forcibly closed by the remote host] 
    System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +6132200 
    System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +134 

[IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.] 
    System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +300 
    System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size) +26 
    System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead) +265 

[WebException: The underlying connection was closed: An unexpected error occurred on a receive.] 
    System.Net.HttpWebRequest.GetResponse() +6038435 
    ClassLib.HandlerFactory.AjaxProxy.ProcessRequest(HttpContext context) in ClassLib\HandlerFactory.cs:75 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75 

在我看来,这个线

System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +6132200 

表明,试图发送可怕的大量字节 - 为什么是这样?

更新:在我的客户的web.config结合如下:

<bindings> 
    <basicHttpBinding> 
    <binding name="BasicHttpBinding_Api" closeTimeout="00:01:00" 
     openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
     allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
     maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" 
     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
     useDefaultWebProxy="true"> 
    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
    <security mode="None"> 
     <transport clientCredentialType="None" proxyCredentialType="None" 
     realm="" /> 
     <message clientCredentialType="UserName" algorithmSuite="Default" /> 
    </security> 
    </binding> 
    <binding name="ApiBinding" closeTimeout="00:01:00" 
     openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
     allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
     maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" 
     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
     useDefaultWebProxy="true"> 
    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     <security mode="None"> 
     <transport clientCredentialType="None" proxyCredentialType="None" 
      realm="" /> 
     <message clientCredentialType="UserName" algorithmSuite="Default" /> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 

服务器的web.config绑定是:

<bindings> 
    <basicHttpBinding> 
    <binding name="ApiBinding" /> 
    </basicHttpBinding> 
    <webHttpBinding> 
    <binding name="ApiBinding" /> 
    </webHttpBinding> 
</bindings> 

/卡斯滕

+0

你的装订我的朋友是什么?你能告诉我们吗?什么是安全? – Aliostad 2011-05-03 10:47:53

+0

我现在在问题文本的底部添加了web.config中的绑定。谢谢 – 2011-05-03 11:30:07

+0

任何想法?我试图返回简单的类型 - 例如。一个int - 并且工作正常。 – 2011-05-03 13:13:32

回答

0

通过你的信息提供这似乎只是服务器端,这是不可能说出什么问题。

所以:

  • 更新与客户端详细

的信息现在,这个错误告诉我,有是有约束力的错配或安全错误发生 - 虽然安全性设置为无。因此,基于提供的信息,我的预感是客户端和服务器之间的绑定不匹配,可能安全性是针对其他服务器的。

+0

其实我第一次发布的web.config是客户端配置。我现在已经更新了服务器web.config绑定 - 它的信息少得多。我现在还不是很精通......他们需要精确匹配吗? – 2011-05-04 06:28:20

相关问题