关于webService提示An endpoint configuration...的问题

在silverlight中使用webService如果你两次以上删除同一个服务同时再添加该服务的情况下,程序在调试阶段会报错。错误提示为:

An endpoint configuration section for contract 'ServiceReference1.Service' could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name.

因为之前没接触过WSDL文件,对于WSDL文件报错还是有点束手无策。我就直接复制这个错误到google中搜索,后来发现搜索结果都是WCF的样式,还是看不懂。一段时间后我再次读这个错误,这个错误说 

because more than one endpoint configuration for that contract was found

代表有多个终结点存在,需要显示指定使用哪个。再参考WCF中的解决方案(在此不罗列)于是我找到webService中的配置文件(注意是配置文件.svcinfo为后缀,而不是WSDL文件)webService在vs中显示的样式如下图

       

查看该配置文件如下

 <?xml version="1.0" encoding="utf-8"?>
<configurationSnapshot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:schemas-microsoft-com:xml-wcfconfigurationsnapshot">
  <behaviors />
  <bindings>
    <binding digest="System.ServiceModel.Configuration.BasicHttpBindingElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:<?xml version="1.0" encoding="utf-16"?><Data maxBufferSize="2147483647" name="CompareChartServiceSoap11Binding5"><security mode="None" /></Data>" bindingType="basicHttpBinding" name="CompareChartServiceSoap11Binding5" />
  </bindings>
  <endpoints>
    <endpoint normalizedDigest="<?xml version="1.0" encoding="utf-16"?><Data address="http://localhost:8080/axis2/services/CompareChartService" binding="basicHttpBinding" bindingConfiguration="CompareChartServiceSoap11Binding5" contract="CompareChartService.CompareChartServicePortType" name="CompareChartServiceHttpSoap11Endpoint5" />" digest="<?xml version="1.0" encoding="utf-16"?><Data address="http://localhost:8080/axis2/services/CompareChartService" binding="basicHttpBinding" bindingConfiguration="CompareChartServiceSoap11Binding5" contract="CompareChartService.CompareChartServicePortType" name="CompareChartServiceHttpSoap11Endpoint5" />" contractName="CompareChartService.CompareChartServicePortType" name="CompareChartServiceHttpSoap11Endpoint5" />
  </endpoints>
</configurationSnapshot>


这个文件是没问题的,要解决该错误就得在原来声明终结点的时给构造函数指定一个参数

原来使用的是默认构造函数

ServiceEndpoint ep = new PAS.I1Service.CompareChartService.CompareChartServicePortTypeClient().Endpoint;


现在则在构造函数中明确endpoint的名称

ServiceEndpoint ep = new PAS.I1Service.CompareChartService.CompareChartServicePortTypeClient("CompareChartServiceHttpSoap11Endpoint5").Endpoint;

从此次错误中发现,很多新错误确实从来都没接触过,此时不要急于地去搜索解决方案,而是先完全理解错误是什么。这样解决错误的效率就会高一些!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值