2015-10-05 32 views
1

我嘗試調用Web服務。我在Visual Studio https://gate.smsclub.mobi/soap/soapGateway.wsdl添加引用Web服務,我嘗試從這個服務調用的方法我有例外(在這個截圖除外)http://s020.radikal.ru/i709/1510/a6/32a6d38ecf7a.png 我的代碼:當我調用Web服務時出現無效操作異常Visual Studio

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> 

+0

@anekcahap你可以採取錯誤的截圖中英文 – Webruster

+0

異常類型「System.InvalidOperationException」出現在System.ServiceModel.dll,但它並沒有在用戶處理代碼 有關詳細信息:無法找到名稱爲「smsGatewayPort」和合同「ServiceReference1.smsGatewayPortType」部分的端點元素客戶端配置 –

+0

請參閱此[鏈接](http://www.paraesthesia.com/archive/2008/11/) 26 /讀WCF配置-從-A-定製location.aspx /) – Webruster

回答

1

感謝所有 「smsGatewayPortType」!我解決了我的問題其他方法。在Visual Studio中,點擊添加服務引用 - >高級 - >在我調用方法後,在Web服務上添加服務引用和過去鏈接並且它可以工作

0

我們需要手動完成。這Link將告訴如何手動加載配置並創建一個CustomChannelFactory<>來解決此錯誤。

0

使用合同=代替合同= 「ServiceReference1.smsGatewayPortType」

0

來自АлександрТур的awnser幫助了我。

我也有過System.InvalidOperationException,當我在Visual Studio中嘗試自制Web服務時。

在VS2017

你必須去:

項目 - >添加服務引用... - >高級 - >添加Web引用...

有你有到把URL Web Service的下Web引用名您可以更改名稱,然後單擊添加引用

然後你可以使用我們的WebService是這樣的:

referenceName.WebService1 ws = new referenceName.WebService1(); 
ws.doThingsMethod(); 
相關問題