silverlight中如何动态设置wcf服务的服务器名称
我需要部署一个 silverlight 4 解决方案,它使用来自 WCF 服务的数据。挑战在于这将是生产安装,因此我无法控制服务的服务器名称,并且 silver light 应用程序不会安装在与 WCF 相同的服务器上。
从这里开始,我到目前为止已经想到了:
我必须通过 initParams 将 WCF 的服务器名称传递到我的 silverligth 应用程序。
在 aspx 文件中,
<param name="initparams" value="servicepoint=http://myservice" />
然后在 app.xaml.cs 中 我调用参数:
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new MainPage(e.InitParams); //pass parameter from html direclty to main page
}
我在应用程序启动中调用它,因此参数将在整个应用程序的范围内。
现在,在主页中,我将此参数分配给变量
dswconnection = initParams["servicepoint"];
,然后每当我查询服务时,我都会设置地址以覆盖服务refernece.config 文件中的默认值
QueryClient selAct = new QueryClient("BasicHttpBinding_IQuery");
selAct.Endpoint.Address = new System.ServiceModel.EndpointAddress(dswconnection);
我的问题是......这是最好的方法还是有另一种方法可以在您不知道服务器名称是什么时动态识别服务的服务器名称。这是关键点,我无法使用某些功能来检测 ChannelFactory 中的主机名或地址,因为 silverlight 应用程序将驻留在与 WCF 不同的主机上。
现在,传递给 initparams 的值存储在一个配置文件中,该文件由 javascript 读取,然后分配为该值。在我的代码中,为了简洁起见,我对其进行了硬编码。
感谢您的任何建议。
I need to deploy a silverlight 4 soltution where it consumes data from a WCF service. The challenge is this will be a production install and so I have no way of controlling the server name of the service and the silver light app will not be installed on the same server as the WCF.
Starting down this path here is what I have come up with thus far:
I will have to pass the server name of teh WCF to my silverligth app via initParams.
within the aspx file I have
<param name="initparams" value="servicepoint=http://myservice" />
then within the app.xaml.cs
I call the param:
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new MainPage(e.InitParams); //pass parameter from html direclty to main page
}
I called this within app startup so the paramater would be in scope of the entire app.
Now within main page I assign this param to a variable
dswconnection = initParams["servicepoint"];
and then whenever I query the service I set the address to override what is defaulted within the service refernece.config file
QueryClient selAct = new QueryClient("BasicHttpBinding_IQuery");
selAct.Endpoint.Address = new System.ServiceModel.EndpointAddress(dswconnection);
My question is.... is this the best approach or is there another way to dynamically identify the server name of a service when you don't know what that server name could be. This the key point I can't use some of the features to detect host name or address within channelfactory as the silverlight app will reside on a different host than the WCF.
Right now the value that is passed to initparams is stored in a config file that is read by javascript and then assigend as the value. In my code here I hard coded it for brevity.
Thanks for any suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过更多研究后,它出现在 sl 应用程序要安装在单独的服务器上的情况下,或者如果需要让它指向不同的 WCF 端点,则上述方法最适合该项目。我们最终将端点的完整限定服务器名称与其他连接字符串一起存储在 web.config 文件中。然后使用 JSON 将此值传递给 init params。然后,Silverlight 能够在初始化时获取新的服务器名称并将 SL 应用程序指向新服务。
After some more research it appears in instances where the sl app is to be installed on separate servers or if hte need is to have it point to different WCF endpoints the above approach worked the best for this project. We ended up storing the full qualified server name for the endpoin in a web.config file with other connection strings. Then passed this value to the init params using JSON. Silverlightwas then able at intializtion to pick up the new server name and point the SL app towards the new service.
我所做的是使用 zip 打开 xap 文件,然后手动更新端点 servicereference.clientconfig 文件,然后再 zip 回来。
what i did is to open the xap file with zip, then update end point the servicereference.clientconfig file manually, then zip back.