繁体   English   中英

调用Web服务Visual Studio时出现无效的操作异常

[英]invalid operation exception when I calling web service Visual Studio

我尝试致电网络服务。 我在Visual Studio https://gate.smsclub.mobi/soap/soapGateway.wsdl中添加了对Web服务的引用,并且尝试从该服务调用方法,但我有异常(此屏幕截图除外) http://s020.radikal.ru /i709/1510/a6/32a6d38ecf7a.png我的代码:

smsGatewayPortTypeClient sms = new smsGatewayPortTypeClient("smsGatewayPort");

app.config文件

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="smsGatewayBinding" />
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://gate.smsclub.mobi/soap/" binding="basicHttpBinding"
            bindingConfiguration="smsGatewayBinding" contract="ServiceReference1.smsGatewayPortType"
            name="smsGatewayPort" />
    </client>
</system.serviceModel>

谢谢大家! 我用其他方法解决了我的问题。 在Visual Studio中,我调用方法后,单击添加服务引用->高级->添加服务引用和Web服务上的过去链接,它可以正常工作

我们需要手动进行。 链接将告诉您如何手动加载配置并创建CustomChannelFactory<>来解决此错误。

使用contract =“ smsGatewayPortType”代替contract =“ ServiceReference1.smsGatewayPortType”

АлександрТур的遮阳棚帮助了我。

当我在Visual Studio中尝试自己制作的Web服务时,我也遇到了System.InvalidOperationException。

在VS2017中,您必须转到:

项目->添加服务参考...->高级...->添加Web参考...

您必须在其中放置 Web服务的URL ,并在Web引用名称下可以更改名称,然后单击“添加引用”。

然后,您可以像这样使用我们的WebService:

referenceName.WebService1 ws = new referenceName.WebService1();
ws.doThingsMethod();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM