Silverlight应用程序无法访问其他计算机上的WCF服务

编程入门 行业动态 更新时间:2024-10-16 00:18:22
本文介绍了Silverlight应用程序无法访问其他计算机上的WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个Silverlight应用程序,该应用程序运行良好,可以访问Silverlight应用程序本身中托管的WCF服务。它使用的端口是1794。

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.

当我部署到其他服务器(开发,测试或登台)时,应用程序无法访问WCF服务。

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

这是我的ServiceReference.ClientConfig的一个片段,

This is a snippet from my ServiceReference.ClientConfig looks like

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

我的根文件夹也包含clientaccesspolicy.xml文件。

My root folder contains the clientaccesspolicy.xml file too.

如何解决这个问题?

推荐答案

我怀疑 localhost:1794 会引起问题-当Silverlight应用程序在客户端计算机上执行时,本地主机不会将其返回给服务器。

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.

该技术我用来消除此类问题的方法是,以编程方式在运行时设置终点。我需要的两条信息是服务的Web项目在我的Web项目中的位置(这是提前知道的),以及从中提供了Silverlight应用程序的地址(域)(我可以找到)。

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)); }

在这段代码中,文件夹 / WebServices 是我的Web服务位于我的Web应用程序中的位置。然后,我这样调用该函数:

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");

我的实际设置比这稍微复杂一些,因为我也希望能够覆盖它,并且手动配置终点,但是您已经明白了。通过这样做,我已经能够部署到各种设置,并且Web服务器在奇数端口上运行,并且silverlight-> webservice位每次都可以使用。

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.

更多推荐

Silverlight应用程序无法访问其他计算机上的WCF服务

本文发布于:2023-10-07 13:17:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469488.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   无法访问   其他计算机   Silverlight   WCF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!