开发者

WCF error - connection is closed by remote host

开发者 https://www.devze.com 2023-03-02 17:20 出处:网络
I have this very strange error... I am developing on a WCF service, that I\'ve taken over from somebody else. There is a class called User defined like this:

I have this very strange error...

I am developing on a WCF service, that I've taken over from somebody else. There is a class called User defined like this:

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;
        }

etc...

I've made a API method, that returns this object as data

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

When I try to call this from a client, I get this error:

[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

It looks to me that this line

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

indicates, that an awful lot of bytes is tried to be sent - why is that?

UPDATE: The binding in my CLIENT web.config is as follows:

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_Api" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnL开发者_Python百科ocal="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 are:

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

/ Carsten


By the information you have provided which seems to be only server side, it is impossible to say what the problem is.

So:

  • Update the information with the client side detail

Now, the error tells me that there is a binding mismatch or security error happening - although security is set to None. So my hunch based on the info provided is a binding mismatch between client and server possibly security is on for one and off for the other.

0

精彩评论

暂无评论...
验证码 换一张
取 消