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

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

内容简介:把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)));

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

查看所有标签

猜你喜欢:

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

PHP for the World Wide Web, Second Edition (Visual QuickStart Gu

PHP for the World Wide Web, Second Edition (Visual QuickStart Gu

Larry Ullman / Peachpit Press / 2004-02-02 / USD 29.99

So you know HTML, even JavaScript, but the idea of learning an actual programming language like PHP terrifies you? Well, stop quaking and get going with this easy task-based guide! Aimed at beginning ......一起来看看 《PHP for the World Wide Web, Second Edition (Visual QuickStart Gu》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

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

在线 XML 格式化压缩工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具