大佬教程收集整理的这篇文章主要介绍了wcf – Silverlight:当放置在xap中时如何设置ServiceReferences.ClientConfig,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
但是,这个文件包含在xap文件中,而不是在部署应用程序时可以轻松更改的内容.有没有另一种方法从Silverlight应用程序中引用wcf服务?或者如何更改xap文件中的serviceReferences.CLIENtConfig?
在Web应用程序的Web.config中,在AppSetTings中添加一个变量并存储基本URL,请注意,我没有存储SVC文件的位置,稍后我将附加.这是因为我有多个SVC,我通常指向.你可以选择不同的做法.
<appSetTings> <add key="serviceURI" value="http://localhost:64457/"/> </appSetTings>
在我的Web应用程序的Web页面中,添加一个名为InitParms的参数,这样可以添加一个键值对(由逗号分隔,由XAP文件读取)
<div id="silverLightcontrolHost"> <object data="data:application/x-silverlight," type="application/x-silverlight-2" width="100%" height="100%" ID="Xaml1" > <param name="InitParams" value="serviceURI=<%= ConfigurationManager.AppSetTings("serviceURI") %>" />
在Silverlight App.xaml.vb中,将所有的InitParms加载到资源或者你想要的地方
Private Sub Application_Startup(ByVal o As Object,ByVal e As StartupEventArgs) Handles Me.Startup If e.InitParams Isnot Nothing Then For Each k As Generic.KeyValuePair(Of String,String) In e.InitParams Me.resources.Add(k.Key,k.value) Next End If
然后在任何我的XAML文件中,我可以使用配置的URI初始化服务,我有一个这样的方法
Private Sub Initializeservice() Dim uri As String = App.Current.resources("serviceURI") If uri Is Nothing OrElse uri = String.Empty Then 'if there is no value added in the web.config,I can fallBACk to default values _client = New serviceClient Else 'Notice I hardcoded the LOCATIOn of the SVC files in the client and append there here,you may choose not to do this Dim uri_withservice As String = uri & "svc/secure/service.svc" _client = New serviceClient("CustomBinding_service",New EndpointAddress(uri_withservicE)) End If End Sub
以上是大佬教程为你收集整理的wcf – Silverlight:当放置在xap中时如何设置ServiceReferences.ClientConfig全部内容,希望文章能够帮你解决wcf – Silverlight:当放置在xap中时如何设置ServiceReferences.ClientConfig所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。