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

时间:2015-10-05 07:08:09

标签: c# visual-studio wcf

我尝试调用Web服务。我在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>

4 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

使用contract =“smsGatewayPortType”而不是contract =“ServiceReference1.smsGatewayPortType”

答案 3 :(得分:0)

来自АлександрТур的芒果帮助了我。

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

在VS2017中你必须去:

  

项目 - &gt;添加服务参考... - &gt;高级... - &gt;添加Web引用...

您必须设置网络服务的,并在网络参考名称下,您可以更改名称,然后点击添加参考

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

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {

  NSString * scheme = (NSString*)url.scheme;
  NSString * fbScheme = @"fb123456789";

  if ([fbScheme isEqualToString:scheme]) {
    return [[FBSDKApplicationDelegate sharedInstance]
            application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
  } else {
    //Your other stuff here
  }
}