Self-hosted service -> ChannelFactory timeout when called within same project as host RRS feed

  • Question

  • Hello!

    I am banging my head agains the wall for few hours now.
    It is a really simple scenario, but it is ... grrrr. I shouldn't write this on public forum. :D

    Ok. Here is the story.

    1. Create a simple Library project and add WCF service

    2. Create a simple C# WinForm project and host the service (configuration file was copied from app.config which was auto-created in Library project. Only 1 change has been made to the file (I use WSHttpBinding instead of basicHttpBinding)

    Host is listening at the following endpoints:


    3. Create another WinForm project (Test Client) add button to the form and copy the following code:

    WSHttpBinding myBinding = new WSHttpBinding();
    EndpointAddress myEndpoint = new EndpointAddress("http://localhost:8732/Service1");
    ChannelFactory<IService1> myChannelFactory = new ChannelFactory<IService1>(myBinding, myEndpoint);
    IService1 svcClient = myChannelFactory.CreateChannel();
    MyData m1 = svcClient.GetCurrentData();

    This code is working fine, when I execute it form "TestClient" project.

    If I add this code to same project which hosts the service I get timeout exception when GetCurrentData is called.

    Ok. I must be doing something wrong. So, I add ServiceReference to TestClient project and use proxy to call service method.
    It worked (as expected).

    Then I want to "Hosting" project and add service reference there. Using proxy is *again* giving me timeout.

    Somebody have an idea, what could be wrong?


    Monday, November 18, 2013 1:51 PM

All replies

  • Hi,

    It seems that  you host the wcf service in the self host mode.

    When you add the code to the same project you can not work, because when in the self host mode, we should keep the wcf service is running. But if you add the client the code to the project, when you run the WinForm in visual studio, it will let the service stop. Because one visual stuido can only let one WinForm run in one time. In that way we can run the client WinForm in this way, please right click the WinForm, then click "Open Folder in File Exproler", then click "Bin", then click "Debug", then find the exe file, then let it run. I think it will work.

    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.

    Tuesday, November 19, 2013 2:28 AM
  • Hello!

    The service doesn't stop. It is running all the time. I can connect with another application (IE, telnet,...).

    I am not sure what you meant by "Visual studio can only let one WinForm run at one time".
    I am using only one WinForm.
    I tried running exe file from explorer, but the result was the same.

    However you light another bulb in my head.
    I was thinking: maybe host and client cannot run in the same thread.
    So, I created client proxy in another thread and voila... it worked.

    Could you explain a little further what you meant by "running only one WinForm".
    Maybe there is a connection to my solution.


    Tuesday, November 19, 2013 8:21 AM