I have a WCF service reference in my silverlight application called WCF_Service. Yet, whenever I want to use it in my code, I have to specify the Uri for the reference as such:
Uri uri = new Uri(HtmlPage.Document.DocumentUri, "WcfDataService.svc");
WCF_Service.Entities context = new WCF_Service.Entities(uri);
Why do I need to specify the Uri? I know it is necessary, but doesn’t the service reference know where this service is located to begin with?
It is true that the service reference contains a Uri that was used when you added it and it automatically reused when you update the reference – this is for convenience only though.
You can use the same type of service from many different end points – it’s just a matter of reconfiguring what Uri to use (i.e. switch from testing to production server). And that’s why you as a consumer have to supply the end point – imagine using the same service from two different servers – you don’t want to add two references to your project in this case – right?