WCF错误 - 远程主机关闭连接

时间:2011-05-03 10:38:51

标签: wcf

我有这个非常奇怪的错误......

我正在开发一个WCF服务,我已经接管了其他人。有一个名为User的类,如下所示:

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

表示尝试发送大量字节 - 为什么会这样?

更新:我的CLIENT 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>

SERVER web.config绑定是:

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

/ Carsten

1 个答案:

答案 0 :(得分:0)

根据您提供的信息似乎只是服务器端,不可能说出问题所在。

所以:

  • 使用客户端详细信息更新信息

现在,错误告诉我发生了绑定不匹配或安全错误 - 尽管安全性设置为None。因此,根据提供的信息,我的预感是客户端和服务器之间的绑定不匹配,可能安全性为一个,另一个为安全。

相关问题