none
Communication Exception when transmitting and receiving an object to and from WCF services RRS feed

  • Question

  • I am trying to pass an object from server to client. The object is a DTO. following is the error I get:

    CommunicationException was Caught
    An error occurred while receiving the HTTP response to http://localhost:8733/Design_Time_Addresses/PaymentsCreatorService/Service1/. 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.

    A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in mscorlib.dll
    The thread '<No Name>' (0x1b0) has exited with code 0 (0x0).
    The thread '<No Name>' (0x454) has exited with code 0 (0x0).
    Step into: Stepping over non-user code 'System.Exception.InnerException.get'
    System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: 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)
       --- End of inner exception stack trace ---
       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)
       --- End of inner exception stack trace ---
       at System.Net.HttpWebRequest.GetResponse()
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
    The thread '<No Name>' (0x13fc) has exited with code 0 (0x0).
    The thread '<No Name>' (0xce8) has exited with code 0 (0x0).
    Step into: Stepping over non-user code 'System.Exception.GetStackTrace'

    Following is the code snippet at client side where error is encountered: 
    public System.Type GetPaymentsDTO()
    {
        Type temp = null;
        try
        {
            temp = base.Channel.GetPaymentsDTO();
        }
        catch (CommunicationException ex)
        {
            Console.WriteLine(ex.InnerException);
            Console.WriteLine(ex.StackTrace);
        }
        return temp;
    }

    /*Following is the server side code from the Class implementing the Interface for creating service*/
    public System.Type GetPaymentsDTO()
            {
                return new PaymentsDTO().GetType();
            }
    • Edited by Yogesh36693 Saturday, August 23, 2014 8:31 AM
    • Moved by Kristin Xie Monday, August 25, 2014 8:41 AM
    Saturday, August 23, 2014 8:31 AM

Answers

  • Hi,

    If you use the Http WCF Service, then please try to enter the service address in the IE browser to see if it works.
    If the service does not work, then please try to enable the WCF trace to find the root cause.

    The following configuration taken from MSDN can be applied to enable tracing on your WCF service.

    <configuration>
      <system.diagnostics>
        <sources>
          <source name="System.ServiceModel"
                  switchValue="Information, ActivityTracing"
                  propagateActivity="true" >
            <listeners>
                 <add name="xml"/>
            </listeners>
          </source>
          <source name="System.ServiceModel.MessageLogging">
            <listeners>
                <add name="xml"/>
            </listeners>
          </source>
          <source name="myUserTraceSource"
                  switchValue="Information, ActivityTracing">
            <listeners>
                <add name="xml"/>
            </listeners>
          </source>
        </sources>
        <sharedListeners>
            <add name="xml"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="Error.svclog" />
        </sharedListeners>
      </system.diagnostics>
    </configuration>


    Also it will be better if you can try to post your config file here.

    If the service works, then it seems that there is something wrong with the client connection. Then please try to make sure that the firewall does not break your connection. Besides, please also try to post the client config file here.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, August 27, 2014 10:31 AM
    Moderator
  • Hi Yogesh,

    Based on the code you shared related to client and server methods to connect, I found you are trying to retrun the type of the object. It is not object exactly.

    for this  we can return the string value instead of object type in service call. and we can create a object in client side by using reflection methods

    In server side , the code should be like in below.

    public String GetPaymentsDTO()
            {
                return new PaymentsDTO().GetType().ToString();
            }

    Once you received the type of the object type in string format then, you can create a onject in client side by refernce of contracts you shared through service metadata.



    prabakaran.M


    Thursday, August 28, 2014 5:30 AM

All replies

  • You should post to the MSDN WCF forum. I would give you the link but I am posting from my tablet.

    Saturday, August 23, 2014 12:56 PM
  • Hi,

    If you use the Http WCF Service, then please try to enter the service address in the IE browser to see if it works.
    If the service does not work, then please try to enable the WCF trace to find the root cause.

    The following configuration taken from MSDN can be applied to enable tracing on your WCF service.

    <configuration>
      <system.diagnostics>
        <sources>
          <source name="System.ServiceModel"
                  switchValue="Information, ActivityTracing"
                  propagateActivity="true" >
            <listeners>
                 <add name="xml"/>
            </listeners>
          </source>
          <source name="System.ServiceModel.MessageLogging">
            <listeners>
                <add name="xml"/>
            </listeners>
          </source>
          <source name="myUserTraceSource"
                  switchValue="Information, ActivityTracing">
            <listeners>
                <add name="xml"/>
            </listeners>
          </source>
        </sources>
        <sharedListeners>
            <add name="xml"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="Error.svclog" />
        </sharedListeners>
      </system.diagnostics>
    </configuration>


    Also it will be better if you can try to post your config file here.

    If the service works, then it seems that there is something wrong with the client connection. Then please try to make sure that the firewall does not break your connection. Besides, please also try to post the client config file here.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, August 27, 2014 10:31 AM
    Moderator
  • Hi Yogesh,

    Based on the code you shared related to client and server methods to connect, I found you are trying to retrun the type of the object. It is not object exactly.

    for this  we can return the string value instead of object type in service call. and we can create a object in client side by using reflection methods

    In server side , the code should be like in below.

    public String GetPaymentsDTO()
            {
                return new PaymentsDTO().GetType().ToString();
            }

    Once you received the type of the object type in string format then, you can create a onject in client side by refernce of contracts you shared through service metadata.



    prabakaran.M


    Thursday, August 28, 2014 5:30 AM