Silverlight application cannot access WCF services on other machines

前端 未结 1 1895
渐次进展
渐次进展 2020-12-20 01:01

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.

相关标签:
1条回答
  • 2020-12-20 01:18

    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.

    0 讨论(0)
提交回复
热议问题