Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello everybody.
I wrote some code in WCF, I have a server and clients that connect to the server.

I have some client that works in Console, and it works very well, but I have been try to write some client in winForm, (the code is almost the same as the console one except the line that use Console.WriteLine())
I get an exception after 1 minute (TimeOutException).

Here is the code in Console and in winForm. This code works properly,in Console:
C#
ServerEvents myCallbacks = new ServerEvents();

            DuplexChannelFactory<IStringReverser> pipeFactory =
               new DuplexChannelFactory<IStringReverser>(
                  myCallbacks,
                  new NetTcpBinding(),
                  new EndpointAddress(
                     "net.tcp://localhost/PipeReverse"));

            IStringReverser pipeProxy = pipeFactory.CreateChannel();

            while (true)
            {
                string str = Console.ReadLine();
                Console.WriteLine("pipe: " +
                  pipeProxy.ReverseString(str));
            }


That one throws an exception. Supposed to work in winform:
C#
ServerEvents myCallbacks = new ServerEvents();

            DuplexChannelFactory<IStringReverser> pipeFactory =
               new DuplexChannelFactory<IStringReverser>(
                  myCallbacks,
                  new NetTcpBinding(),
                  new EndpointAddress(
                     "net.tcp://localhost/PipeReverse"));

            IStringReverser pipeProxy = pipeFactory.CreateChannel();



                string str = "asaf maimon";
                try
                {
                    str = pipeProxy.ReverseString(str);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

I'd be happy if someone could find the problem.
Thank you all.

EDIT =============

Well here is my exception...

Could not connect to net.tcp://localhost/PipeReverse. The connection attempt lasted for a time span of 00:00:02.0190000. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:808.
Posted
Updated 14-Sep-10 6:10am
v3

Well, the first thing I would do is refactor the code. A lot of the changes I did were simply to serve the page width limitations here on CP as well as to ease debugging, but the key is to put a try/catch block around ALL of the code. With the code below, you can now step through the code and verify that all of the objects you're creating are valid, as well as find out what's failing:

C#
public class PipeFactory : DuplexChannelFactory<IStringReverser>{} <br />

public partial class MyForm
{
    private void MyMethod()
    {
        try
        {
            ServerEvents myCallbacks  = new ServerEvents();
            NetTcpBinding binding     = new NetTcpBinding();
            EndpointAddress endPoint  = new EndpointAddress("net.tcp://localhost/PipeReverse");

            PipeFactory pipeFactory   = new PipeFactory(myCallbacks, binding, endpoint);
            IStringReverser pipeProxy = pipeFactory.CreateChannel();
 
            string str = pipeProxy.ReverseString("asaf maimon");
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
}
 
Share this answer
 
v4
A couple of suggestions:
1) set a breakpoint on the error and examine the exception for more details. Timeouts are often self-revealing.

2) make sure the service is still running. If you switched from a console app to a winforms app, what did you do to port the service? Is it still on the same port? Is it deployed to IIS locally?

3) check your windows logs. If exceptions are being thrown in IIS they'll likely end up there and may not make it back alive to your app.

Cheers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900