WCF between two Apps (NO website involved - Thank Goodness) RRS feed

  • Question

  • Hello again, Gurus.

    Quickie question here (or maybe two or three questions). I've read that it is possible to use WCF between two C# apps using "net.tcp".    Now the LAST thing in the world I want to do is write web code but I'd love to try WCF between apps, especially with net.tcp.

    So my question(s) is(are)

    1. If one agrees to avoid anything having even the remotest, most obscure relationship with a website, does one still need to load IIS and (I mean, My God, have you SEEN those instructions ?)

    2. Would you refer me to any tutorials available on line (or in a commercially available book) that describe writing WCF code between two C# apps ? (while avoiding even the mention of the word 'web' or 'http:').

    Thanks for your help.

    Tuesday, May 5, 2015 8:12 PM


All replies

  • I know this will sound like a contractor speaking, but the answer to your question is, it depends. I've written WCF services which use net.tcp. They worked fine. However I was working with a Windows Server 2003 at the time. Something has to host the WCF service, and when I was starting out writing the WCF service I had hoped that I IIS could host it. I knew that IIS is capable of doing that. However IIS under Windows Server 2003 is not capable of hosting anything else unless it's serves up HTML. But there is a work around, which I found. What you have to do is write a Windows Service, and that Windows Service can host your WCF service that uses net.tcp just fine. That's what I did, and it works.


    Tuesday, May 5, 2015 8:17 PM
  • 1) WCF does not depend on IIS, and you can self-host a service in a Windows Desktop Application (WinForms, WPF or Console), or a Windows Service.

    2) There's a sample here, or just search for "WCF Self-Host"



    Tuesday, May 5, 2015 8:37 PM
  • Gentlemen,

    Thank you so much for your help ... I was on the verge of tears just thinking about ASP.NET, IIS, and websites.

    What I have in mind is the User's executable (client) which will connect to my server (probably a separate executable, but Boy,  wouldn't a DLL-resident server be nice?), either on the same machine as localhost, or on a separate machine.

    But right now, the heck with Computer Science, let's just get this thing going.    I'm just trying to get this thing off the ground.

    Thanks very much for your help Gentlemen.

    Tuesday, May 5, 2015 8:51 PM
  • You're welcome. :)


    Tuesday, May 5, 2015 9:19 PM
  • In the link are the various communication protocols WCF can use with HTTP being one of them.

    Wednesday, May 6, 2015 11:50 PM
  • Below is a good article which walks you through the process of hosting a WCF service within a Microsoft Windows service.

    Friday, May 8, 2015 3:10 AM
  • Friday, May 8, 2015 4:28 AM
  • Hi Bonnie.  With your help and that of the other contributors here, I managed to get over the initial problem;  now on to the next (and much larger) problem ...

    I am required to use Port-Sharing. I have indeed been following Microsoft's MSDN topics, and I think I might have a server that works, or is on the verge of working ... but I don't see much that describes how a client should use WCF to connect to a port-sharing server.  I need to send a request to add two numbers (I'm using Microsoft's 'calculator' example as my server).

    I tried hacking my client from the explicit-port example which now works (with your and everyone else's help), but that was NoGo.   Microsoft threw an exception with the message

    "{"Could not find a base address that matches scheme http for the endpoint with binding WSHttpBinding. Registered base address schemes are []."}"


    (a) do I want to be using WSHttpBinding or NetTcpBinding, and 

    (b) do you have an example of registering a base address (the server's ...  the client's ... or both ?).

    I didn't see a mention of 'registering' a base address on your blog ... did I miss something ?

    and finally, once a client is connected, what is the format to 'call' the server's 'add' function and receive the sum ?

    I should also mention that this is a self-host model ... IIS is not involved.



    • Edited by Lincoln_MA Sunday, May 10, 2015 6:32 PM
    Sunday, May 10, 2015 6:28 PM
  • Hi Bill,

    This is a bit of thread drift, so if we don't solve this problem within the next post or so, you should probably start a new question thread.

    But first, let me say that you should be using NetTcpBinding (did you read this article:

    Try that first, and if it still doesn't work, post your Config file here (or start a new thread and post the link to the new thread here, so that those who are interested can easily find you new question).

    ~~Bonnie DeWitt [C# MVP]

    Sunday, May 10, 2015 10:29 PM
  • Also why are you "required to use Port-Sharing"?  It's only for hosting multiple, separate WCF NetTcpBinding services on the same listening port.  Is that really your scenario?

    All the HTTP-based WCF transports support this too, as the low-level TCP/IP processing is handled by the Windows Kernel (HTTP.SYS); so you can host multiple HTTP-based services and web-sites on the same port, and Windows will dispatch the incoming connections based on URL reservations.



    Monday, May 11, 2015 2:42 PM
  • I am required to use port sharing because this little calculator app is not the ultimate goal ... and indeed, given a choice, I would not have used Port-Sharing (While I can and do admire what it does, it's just SO PAINFUL to use, whereas .NET makes conventional network programming essentially easy; I can do it in my sleep).

    So my calculator app is nothing more than a pedagogical stepping stone on the way to the ultimate goal which, management deemed, SHALL (not WILL ... SHALL) incorporate Port-Sharing.

    Bummer, Man.

    I have started a new thread SOMEwhere on MS forums with a bit more detail, but wherever it is now, I can't find it.

    • Edited by Lincoln_MA Monday, May 11, 2015 4:28 PM
    Monday, May 11, 2015 4:06 PM
  • >I have started a new thread SOMEwhere on MS forums with a bit more detail, but wherever it is now, I can't find it.

    You can find all your activity under your profile link.



    Monday, May 11, 2015 5:09 PM