Silverlight application cannot access WCF services on other machines

て烟熏妆下的殇ゞ 提交于 2019-11-29 12:12:40

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!