none
WCF Service Address questions

    Question

  • (1) Can someone tell me what the significance of the service port number?  For example, when I create a default WCF service and right click on the Service.svc file and ask to view it in the browser, I see an address like:

    http://localhost:59389/Service.svc

    I never mentioned anything about "59389". Where does this come from?  I know that if I don't specify endpoints, WCF will give me default endpoints with default addresses.   How does it pick the arbitrary number "59389"?  This number also pops up in the App.config of a client when I add the service reference.  However, when publish the web site to IIS (by clicking on the web site project and choosing "Publish Web App") it gives me an IIS address without the port number, e.g. http://localhost/test/Service.svc  (where "test" is the IIS web directory).  I know that if create a web site from scratch in IIS, it gives me the option to specify a port number, so ports must have significance in actual deployment as well.

    So exactly what is the port number used for and when do I need it?

    (2)  I created a web service and client in code-only.  I specified the address in the service and client as:

        string address = @"http://localhost:8000/Greetings";

    Then I created my ServiceHost as:

    using (ServiceHost host = new ServiceHost(typeof(GreetingsService), new Uri(address)))

    The client successfully communicates with the service.  Just for fun, I then changed the address in the service to:

    string address = @"http://garbage:8000/Greetings";

    I do not use "garbage" anywhere else.  I did not make any changes to client.  Everything still worked fine.  Why is that?  Should this not have failed?  What is the significance of the string "localhost" and why can it arbitrarily be changed?

    Thanks for any help you can give.


    • Edited by joeprog2 Wednesday, December 06, 2017 7:29 AM
    Wednesday, December 06, 2017 7:26 AM

Answers

  • Hi joeprog2,

    It is strange for your current WcfService in WcfHelloWorldWithConfigFiles, and it is different from WCF Service that I created by New Project->WCF->WCF Service Application.

    For current WcfService, you could check the port by Right-click WcfService-> Properties Window->URL.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by joeprog2 Friday, December 08, 2017 6:48 AM
    Friday, December 08, 2017 6:27 AM
    Moderator

All replies

  • Hi joeprog2,

    There are two issues in your post, I would suggest you repost the second issue in a new thread, and then we could focus the specific issue in one thread.

    >> So exactly what is the port number used for and when do I need it?

    For this issue, port is a part of URL address and could not be miss. You need it all the time.

    >> I never mentioned anything about "59389". Where does this come from?

    For this scenario, you launch WCF Service from VS which host WCF Service in IIS Express, you could find the port setting by Project properties-> Web->Servers->Project Url.

    >> How does it pick the arbitrary number "59389"?

    This port number is randomly picked from unused ports when you created WCF Service in IIS.

    >> when publish the web site to IIS (by clicking on the web site project and choosing "Publish Web App") it gives me an IIS address without the port number

    When you publish web app, it default published to the web site whose port number is 80, and for 80 port, it could be hide in the url.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 07, 2017 2:31 AM
    Moderator
  • I submitted question (2) on a separate post as you suggested.

    I have the following comments regarding question (1):

    I am assuming that if you do't specify a port then it automatically assumes a number of 80, that is, "http://localhost/test/Service.svc" is actually  "http://localhost:80/test/Service.svc".  Is this correct?

    Why do I need port numbers, i.e. if we wanted to implement two web addresses  then instead of:

    http://localhost:59389/test1/Service.svc

    http://localhost:59390/test1/Service.svc

    We could have:

    http://localhost/test1/Service.svc

    http://localhost/test2/Service.svc

    What advantage do I get from the use of port numbers?

    I do not  understand your comment: "you could find the port setting by Project properties-> Web->Servers->Project Url."  Do I look in Visual Studio for this or in IIS Manager.  In IIS Manager I was able to see the port setting below (see the far right side of image).  Is this what you were referring to?

    Thursday, December 07, 2017 10:10 PM
  • Hi joeprog2,

    >> Is this correct?

    Yes, it is.

    >> What advantage do I get from the use of port numbers?

    Port is used to identify specific services. For http://localhost/test1/Service.svc, it’s port is 80, so there is no difference from http://localhost:59389/test1/Service.svc on URL Format, they are communicated between different port.

    >> Is this what you were referring to?

    It’s in VS.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 08, 2017 2:49 AM
    Moderator
  • What did you click on in Visual Studio to get the above screen?  I right-clicked on the web project and neither the choice Property Window nor Property Pages showed the above screen.
    Friday, December 08, 2017 4:58 AM
  • I followed Project properties-> Web->Servers->Project Url, could you share us a screen shot about your project Property window?

    It would be helpful if you could share us a project which could reproduce your issue.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 08, 2017 5:06 AM
    Moderator
  • Here is the link to the sample project.
    Friday, December 08, 2017 6:17 AM
  • Hi joeprog2,

    It is strange for your current WcfService in WcfHelloWorldWithConfigFiles, and it is different from WCF Service that I created by New Project->WCF->WCF Service Application.

    For current WcfService, you could check the port by Right-click WcfService-> Properties Window->URL.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by joeprog2 Friday, December 08, 2017 6:48 AM
    Friday, December 08, 2017 6:27 AM
    Moderator
  • I have the answer now.  I created a WCF Web site (right-click on the solution, choose Add Web Site) and you created a WCF Service Application.  This link explains all the Visual Studio WCF service templates and how they differ.

    I am going to mark this post as answered.  Thank you very much for prompt and accurate assistance.

    Friday, December 08, 2017 6:48 AM