解决 关于Silverlight使用WCF时抛出异常 Could not find default endpoint element that references contract...

环境是这样的

在solution中添加了一个WebSite,在WebSite中添加了一个Silverlight-enabled WCF Service(添加普通的WCF Service,在Silverlight中使用service reference时会报错。但是通过修改config和契约是可以使用的,这里简化背景,只适用Silverlight-enabled WCF Service)。 再向solution中添加一个Silverlight Application,在这个application中添加刚才创建的Silverlight-enabled WCF Service的service reference是可以调用成功的。之后再向solution添加一个Silverlight Library。把这个Library引用到刚才的Silverlight application中。并向Library中添加service reference。这时在这个Library中调用WCF服务会失败。抛出Could not find default endpoint element that references contract...

在网上找啊找也没有好的解决方案,看来只能靠自己了。分析异常报告,有这样一句

This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element。

显然前半句的错误肯定不存在。ServiceReferences.ClientConfig好好的躺在那呢。

那么只能是endpoint element在config中找不到了。尝试着在ClientConfig中将契约添加命名空间,修改绑定类型等等都不起作用。

后来突然想到有Application加载Library,那么会不会需要在Applcation中的ClientConfig添加Library的endpoint呢?于是在Application的ClientConfig中尝试添加Library中用到的endpoint。重新编译,启动。成功调用。。。。。。

怎么说微软好呢。。。。。

总结解决方法,如果要在Silverlight的library中使用WCF需要在Sliverlight Applcation的config文件中添加相应的endpoint

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值