
使用ServiceReferences.ClIEntConfig的方式来实例化WebService代理类比较简单,但是也有一个缺点,就是每次将Silverlight项目上线时都需要手工打开生成的XAF包,将ServiceReferences.ClIEntConfig文件中的WebService地址从http://Localhost/YourProject/YourWebService.asmx的形式改为http://YourDomain/YourProject/YourWebService.asmx,如果某次你忘记了修改,可能会导致你的Siverlight项目在线上无法正常运行。 实现原理很简单,就是在一个类里手工的构造WebService的EndPoint,Binding等信息,将ServiceReferences.ClIEntConfig的作用用代码来代替,示例实现代码如下,代码很简单,各位一看就明白。
///<summary>/// 得到WebService对象/// 以后实例化WebService代理时请用var serviceClIEnt = Utility.GetDesignerServiceInstance();的形式,/// 不要再用默认的 var serviceClIEnt = new WSDesignerSoapClIEnt();/// 后一种形式会报错,因为我们删除了ServiceReferences.ClIEntConfig文件///</summary>///<returns></returns> public static WSDesignerSoapClIEnt GetDesignerServiceInstance() { var basicBinding = new BasichttpBinding() { MaxBufferSize = int.MaxValue,MaxReceivedMessageSize = int.MaxValue,name = "WSDesignerSoap" }; basicBinding.Security.Mode = BasichttpSecurityMode.None; var endPoint = new EndpointAddress(getHostUrl() + "/WebService.asmx"); var ctor = typeof (WSDesignerSoapClIEnt).GetConstructor(new Type[] {typeof (Binding),typeof (EndpointAddress)}); return (WSDesignerSoapClIEnt) ctor.Invoke(new object[] {basicBinding,endPoint}); } ///<summary>/// 得到当前所在网站的根目录,如http://localhost/flow/// 注意站点名字必须是Flow,否则会报错。///</summary>///<returns></returns> private static string getHostUrl() { var location = (HTMLPage.Window.GetProperty("location")) as ScriptObject; var hrefObject = location.GetProperty("href"); string url = hrefObject.ToString().Substring(0,hrefObject.ToString().IndexOf("Flow/") + 5); return url; } PS:本文在写作中参考了:[Silverlight]摆脱对 ServiceReferences.ClIEntConfig 的依赖
本文来自张荣华的博客,原文地址:http://www.cnblogs.com/zhangronghua/archive/2011/11/22/SilverlightRemoveConfigDependency.HTML
总结以上是内存溢出为你收集整理的Silverlight中的ServiceReferences.ClientConfig全部内容,希望文章能够帮你解决Silverlight中的ServiceReferences.ClientConfig所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)