调用Web服务的错误,“该合同的多个端点配置”或“没有端点侦听”

时间:2014-08-15 13:05:06

标签: c# web-services

我刚刚在添加webservice时遇到了问题,它在这个帖子中解决了 error on adding webservice

现在我只是通过调用它的方法

来解决问题

这是我的app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="sedardIPSoap" />
        </basicHttpBinding>
        <customBinding>
            <binding name="sedardIPSoap12">
                <textMessageEncoding messageVersion="Soap12" />
                <httpTransport />
            </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint address="http://service.proapp.ir/service/sedardIP.asmx"
            binding="basicHttpBinding" bindingConfiguration="sedardIPSoap"
            contract="sedardip_set.sedardIPSoap" name="sedardIPSoap" />
        <endpoint address="http://service.proapp.ir/service/sedardIP.asmx"
            binding="customBinding" bindingConfiguration="sedardIPSoap12"
            contract="sedardip_set.sedardIPSoap" name="sedardIPSoap12" />
    </client>
</system.serviceModel>

所以当我尝试像这样调用我的函数时

sedardip_set.sedardIPSoapClient nm = new sedardip_set.sedardIPSoapClient();
nm.set_ip("x1", "x2", "x3");

它抛出此异常

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

所以我尝试从app.config中删除其中一个端点,然后抛出此异常

There was no endpoint listening at http://service.proapp.ir/service/sedardIP.asmx 
that could accept the message. This is often caused by an incorrect address or 
SOAP action. See InnerException, if present, for more details.

内部异常

{"The remote server returned an error: (404) Not Found."}

我只是在我的visual studio(本地)上运行服务,并删除其刚刚工作的第二个端点! 所以任何人都可以帮助我在http://service.proapp.ir/service/sedardIP.asmx plz ??

上工作

1 个答案:

答案 0 :(得分:2)

您是否有理由需要使用网络参考?服务引用是更新的,更新的处理方式,但如果您出于某种原因需要使用Web引用,那么这也很好。

如果您使用服务参考路线,您可以专门命名您要使用的端点,例如:

sedardip_set.sedardIPSoapClient nm = new sedardip_set.sedardIPSoapClient("sedardIPSoap12");
nm.set_ip("x1", "x2", "x3");

在设置服务引用后它可能有一个新名称,但您只需用新名称替换sedardIPSoap12。