2

I have a silverlight application which works perfectly and can access the WCF services which are hosted in silverlight application itself. The port it is using is 1794.

When I deploy to other servers (dev or test or staging), the application is not able to access WCF services.

This is a snippet from my ServiceReference.ClientConfig looks like

<endpoint address="http://localhost:1794/MyWebService.svc"
                binding="customBinding" bindingConfiguration="CustomBinding_MyWebService"
                contract="ConfigMgmtServiceReference.MyWebService"
                name="CustomBinding_MyWebService" />

My root folder contains the clientaccesspolicy.xml file too.

How can I get past this issue?

Cœur
  • 37,241
  • 25
  • 195
  • 267
SVI
  • 1,631
  • 3
  • 22
  • 30
  • So, when you are calling the WCF component from another machine, are you still using the localhost url? That would be a problem right there. You need to be able to address the box running the service. Or am I missing something? – Tad Donaghe Feb 05 '10 at 22:22
  • Terry, Before building the project and publishing to other servers, I change the address in the endpoint. I change it to localhost:1794 to servername/virtualfolder. – SVI Feb 05 '10 at 23:29

1 Answers1

1

I suspect the localhost:1794 would be causing the issue - when the silverlight application executes on a client machine the localhost will not get it back to the server.

The technique i use to eliminate issues like this is to programmatically set the end points at run time. The two pieces of info i need are the location within my web project of the service (which is known ahead of time), and the address (domain) that the silverlight app has been served from (which i can find out).

    private void initEndpoint(ServiceEndpoint endPoint, string serviceName)
    {
        Uri hostUri = Application.Current.Host.Source;
        string wcfBaseUri = string.Format("{0}://{1}:{2}/WebServices/", hostUri.Scheme, hostUri.Host, hostUri.Port);

        endPoint.Address = new EndpointAddress(new Uri(wcfBaseUri + serviceName));
    }

In this piece of code, the folder /WebServices is where my web services are located within my web app. I then call the function like this:

        LoggingServiceClient loggingService = new LoggingServiceClient();
        initEndpoint(loggingService.Endpoint, "LoggingService.svc");

my actual setup is slightly more complex than that, because i also want to be able to override that and manually configure the end points, but you get the point. By doing this, i have been able to deploy to all sorts of setups, with webservers running on odd ports, and the silverlight->webservice bit just works every time.

slugster
  • 49,403
  • 14
  • 95
  • 145