locked
trouble with Self-Host example RRS feed

  • Question

  • Hello folks - Looking to impliment WCF.  I've tried for hours to get the self-host example to work.  The service is running as a console app.  When I run "netstat -a" I see that the machine is listening on port 8000 and the code doesn't throw any exceptions.  However, when I navigate to the following the page isn't found.  
    http://localhost:8000/ServiceModelSamples/service
    Also, the sample client throws an exception saying that it couldn't establish the connection

    I don't have any firewalls running.  Has anyone run into this issue?  I'm pretty much stuck if I can't get a simple service to selfhost.  How can I start to debug this issue?

    Tuesday, May 6, 2008 2:22 AM

Answers

  • Hi,

     

    Yes, this is really weird.

     

    I haven't been able to repro the problem you've been describing on my machine at all. The other thing that's really suspicious is that you're getting an EndpointNotFoundException

     

    In my experience, I've only had that happen to me when I accidentally forgot to turn on the service, when a firewall was up, or I set the endpoint incorrectly on the client or server. One of the things I actually managed to do once was to set the endpoint in both config and in code... I forget which setting won Smile

     

    Another thing that you can use as a sanity check is to start up the service as self hosted, and then try to telnet to the service.

     

    e.g., your service is hosted at http://my-machine:8889/myService/Service1

     

    run: telnet my-machine 8889

     

    You should get a blank telnet session... type some garbage inside there, and press enter. You should get a HTTP response back along the likes of:


    HTTP/1.1 400 Bad Request
    Content-Type: text/html; charset=us-ascii
    Server: Microsoft-HTTPAPI/2.0
    Date: Thu, 22 May 2008 00:01:20 GMT
    Connection: close
    Content-Length: 326

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
    <HTML><HEAD><TITLE>Bad Request</TITLE>
    <META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
    <BODY><h2>Bad Request - Invalid Verb</h2>
    <hr><p>HTTP Error 400. The request verb is invalid.</p>
    </BODY></HTML>

    I'm just throwing any and all hunches and suggestions that I might have... hopefully something in here helps you out Smile

     

    If you're good with closing off the thread, just mark any of the posts above as answered. And when you do get time to re-investigate this, please post back. It'd be interesting for everyone to see what might have happened.

     

    Thanks, and good luck!

    --Jason

    Thursday, May 22, 2008 12:06 AM

All replies

  • Need more details here.  Anything more about the exceptions?  Do you have the sample code somewhere?  Any details about the app.config file and settings?

     

    Tuesday, May 6, 2008 2:29 AM
  • I'm using the WCF sample code from here (specific solution gets copied to: \WCF_WF_CardSpace_Samples\WCF\Basic\Service\Hosting\SelfHost\VB\)

    http://www.microsoft.com/downloads/details.aspx?FamilyId=2611A6FF-FD2D-4F5B-A672-C002F1C09CCD&displaylang=en

    I'm using this code without any modificaitons.b

     

    The client returns the following exception:

    EndpointNotFoundException

    Could not connect to http://localhost:8000/servicemodelsamples/service. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8000.

     

    I'm assuming that that's also the reason why I can't browse to http://localhost:8000/servicemodelsamples/service

     

    The strange thing is that this works perfectly fine on another machine, just not my dev box.

     

    Tuesday, May 6, 2008 3:01 AM
  • Dan - I was able to get this to work if I changed the protocol to TPC instead of HTTP.  Does it help any to know that?

     

    Wednesday, May 7, 2008 4:07 PM
  • Just a shot in the dark here - can you try connecting to the service using your host name instead of localhost?

     

    --Jason

    Monday, May 12, 2008 6:43 PM
  • This just occurred to me.

     

    If you're trying to run the examples from a Visual Studio environment and you're running Windows Vista, ensure that you're running that as Administrator (right-click the VS program icon -> Run as Administrator), then open the project.

     

    Similarly, any command prompt you're running commands for (e.g., netsh) should be run from an elevated command prompt.

    Monday, May 19, 2008 5:39 PM
  • SFunCoder,

     

    Have you managed to get this working?

     

    --Jason

     

    Wednesday, May 21, 2008 11:26 PM
  • Hi Jason - i actually haven't had the time to work this out.   net.tcp is working just great for me.  I'm not running Vista - so the previous suggestion wouldn't be applicable.  I'm sure if I enable tracing I would be able to figure out the problem.  I think i'll just sit on it until I really have to get http to work and then figure it out.  should we close out this thread?

    Wednesday, May 21, 2008 11:51 PM
  • Hi,

     

    Yes, this is really weird.

     

    I haven't been able to repro the problem you've been describing on my machine at all. The other thing that's really suspicious is that you're getting an EndpointNotFoundException

     

    In my experience, I've only had that happen to me when I accidentally forgot to turn on the service, when a firewall was up, or I set the endpoint incorrectly on the client or server. One of the things I actually managed to do once was to set the endpoint in both config and in code... I forget which setting won Smile

     

    Another thing that you can use as a sanity check is to start up the service as self hosted, and then try to telnet to the service.

     

    e.g., your service is hosted at http://my-machine:8889/myService/Service1

     

    run: telnet my-machine 8889

     

    You should get a blank telnet session... type some garbage inside there, and press enter. You should get a HTTP response back along the likes of:


    HTTP/1.1 400 Bad Request
    Content-Type: text/html; charset=us-ascii
    Server: Microsoft-HTTPAPI/2.0
    Date: Thu, 22 May 2008 00:01:20 GMT
    Connection: close
    Content-Length: 326

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
    <HTML><HEAD><TITLE>Bad Request</TITLE>
    <META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
    <BODY><h2>Bad Request - Invalid Verb</h2>
    <hr><p>HTTP Error 400. The request verb is invalid.</p>
    </BODY></HTML>

    I'm just throwing any and all hunches and suggestions that I might have... hopefully something in here helps you out Smile

     

    If you're good with closing off the thread, just mark any of the posts above as answered. And when you do get time to re-investigate this, please post back. It'd be interesting for everyone to see what might have happened.

     

    Thanks, and good luck!

    --Jason

    Thursday, May 22, 2008 12:06 AM
  • I had the same problem and think I figured it out. I created WcfService with C# code configuring the service as explained in topic:
    How to: Host and Run a Basic Windows Communication Foundation Service

    After I had WcfClient working, I changed WcfService to use app.config for the ServiceHost parameters. That's when I started getting the EndpointNotFoundException. It finally occurred to me to regenerate the proxy and that solved the problem. Here are the differences:

    When generated against WcfService with code setup:
                <endpoint address="http://localhost:8000/ServiceModelSamples/Service/CalculatorService"


    When generated against WcfService with app.config setup:
                <endpoint address="http://localhost:8000/ServiceModelSamples/service"

    • Proposed as answer by brian_brane Wednesday, November 25, 2009 4:23 AM
    Wednesday, November 25, 2009 4:22 AM
  • I was stuck up with the same issue. Worked like a charm on running  telnet my-machine 8889 . Thanks a ton Jason.

    Friday, December 31, 2010 7:13 AM