把Silverlight的WCF service配置地址放到web.config中

栏目: ASP.NET · 发布时间: 8年前

内容简介:把Silverlight的WCF service配置地址放到web.config中

如果在Silverlight中使用了WCF service,会生成一个ServiceReferences.ClientConfig配置文件,里面描述了WCF service的地址等信息。最后会放在生成的.xap中,可以用zip软件打开.xap,看到这个文件。

如果开发时的WCF service和部署时的WCF service地址不一样,就需要每次部署时手动修改.xap包中的这个文件,比较麻烦而且容易出错。

一个解决办法是把Service的地址放到web.config中,变成可配置的。然后在调用Siverlight的aspx或者html中通过initParms传给Silvergliht。下面是示例代码:

aspx文件中:

<paramname="initParams"value="wcfServiceUrl=<%=ConfigurationManager.AppSettings["WCFServiceAddress"] %> " />

Silverlight文件初始化WCF Service是不用默认的构造函数,用这种方式:

BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
binding.MaxReceivedMessageSize = int.MaxValue;
binding.MaxBufferSize = int.MaxValue;
ServiceClient sc = new ServiceClient(binding, new EndpointAddress(new Uri(wcfServiceUrl)));

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Inside Larry's and Sergey's Brain

Inside Larry's and Sergey's Brain

Richard Brandt / Portfolio / 17 Sep 2009 / USD 24.95

You’ve used their products. You’ve heard about their skyrocketing wealth and “don’t be evil” business motto. But how much do you really know about Google’s founders, Larry Page and Sergey Brin? Inside......一起来看看 《Inside Larry's and Sergey's Brain》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具