Answered by:

localhost:8080? localhost:8888? localhost:XXXX

Question

I'm new to WCF and have watched a few videos about WCF recently. I'm confused about the address information. Sometimes I see them use localhost:8080, sometimes localhost:8888 and sometimes even localhost by itself. I even see them use localhost:8080/myservice. Why the difference?

Would it not be simpler to use localhost/myservice, all the time, as the base address and then use monikers (offset addresses) for everything else?

Does the address format depend of the type of binding you are using?

Sometimes it appears they pick an address by random. How would you know if there is not another service already at that address?

Answers

So an endpoint has address- format is- [base address] + optional port (unless default 80) + URI. If you are having a requirement to host two services from same department, same company and so on you can always use same base address and port and change the URL. Its a feature/ flexibility. Its like on this machine, this port called 8888 I am going to be listening (waiting) for requests to come in. And if you mention a URI then its like someone called myservice is waiting for requests. So depending on the various other performance/ maintenance/ volume requirements you can make a design decision.

>> Does the address format depend of the type of binding you are using?

yes it does, for http based bindings like basicHttpBinding and wsHttpBinding it starts with http://, whereas for tcp based bindings it starts with net.tcp:// and for msmq it starts with net.msmq://. What follows is [network or machine name or domain] + port + URI

>> Sometimes it appears they pick an address by random. How would you know if there is not another service already at that address?

if the address is generally picked by random then there could be a overlap and host will throw up an error before starting, at least the URI should be different. Its a design/ deployment strategy.

To be honest, more often than not, you would end up using IIS for deployment and in which case you don't have to worry too much because the address would default to the virtual directory/ application in IIS for the svc file. So, if you are self hosting, you have to be a bit careful in documenting and sharing the details with other stakeholders so that they don't accidently use the same ports etc.

All replies

Hi, 1. They are all correct. All Address can be defined as IP(Server name) + port(default 80) +service Host header. So localhost:8080/myservice is correct. They are just a URI,when your define a URI,you should make sure that ,No duplicate URIs. you also can use localhost/myservice,it is using default port 80. 2.Base Address is like its name,It is a base for WCF address. for EXample:http://shipping.myorg.com:8000. You can only define monikers (offset addresses) for your server endpoint,based on the baseaddress. like Adress="WCFService". you also can define a full address without using the baseaddress.Adress="http://shipping.myorg.com:8000/WCFService". 3.You should define a Address for WCF endpoint,if not,WCF will implement a address using baseAddress with http binding. the address by random is just for Visual studio debugging. If another service already at that address,WCF host can not run sucessfully, It will throw a excetion for: There is already a listener on IP endpoint ... So you can not use same address twice. More Address information here:http://msdn.microsoft.com/en-us/library/aa751841.aspx

So an endpoint has address- format is- [base address] + optional port (unless default 80) + URI. If you are having a requirement to host two services from same department, same company and so on you can always use same base address and port and change the URL. Its a feature/ flexibility. Its like on this machine, this port called 8888 I am going to be listening (waiting) for requests to come in. And if you mention a URI then its like someone called myservice is waiting for requests. So depending on the various other performance/ maintenance/ volume requirements you can make a design decision.

>> Does the address format depend of the type of binding you are using?

yes it does, for http based bindings like basicHttpBinding and wsHttpBinding it starts with http://, whereas for tcp based bindings it starts with net.tcp:// and for msmq it starts with net.msmq://. What follows is [network or machine name or domain] + port + URI

>> Sometimes it appears they pick an address by random. How would you know if there is not another service already at that address?

if the address is generally picked by random then there could be a overlap and host will throw up an error before starting, at least the URI should be different. Its a design/ deployment strategy.

To be honest, more often than not, you would end up using IIS for deployment and in which case you don't have to worry too much because the address would default to the virtual directory/ application in IIS for the svc file. So, if you are self hosting, you have to be a bit careful in documenting and sharing the details with other stakeholders so that they don't accidently use the same ports etc.