我是.NET新手,但必須使用VStudio C#2010(.NET 4.0)來生成客戶端,以SOAP Xml方式從Web服務請求數據。我在這裏尋找答案,但更困惑。 MSDN表示,「構建XML Web服務客戶端」是.NET 4.0的遺留問題,即WSDL是遺留問題。他們說,使用「WCF」。 在WCF我迷路了 - 太多,太模糊。它必須更簡單... 我可以在網上找到的所有示例 - 它們都使用WSDL,「遺留」。SOAP xml客戶端 - 使用Visual Studio 2010 c# - 如何?
這裏有我需要以獲得從Web服務的數據使用服務的定義:
要求:
POST /catalog.asmx HTTP/1.1
Host: www.somewebsite.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "https://www.somewebsite.com/KeywordSearch"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<KeywordSearch xmlns="https://www.somewebsite.com/">
<searchTerm>string</searchTerm>
<resultsReturned>int</resultsReturned>
</KeywordSearch>
</soap:Body>
</soap:Envelope>
響應:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
...some stuff...
</soap:Body>
</soap:Envelope>
所以,什麼是建立這個簡單的客戶端的權利,或者至少是最合乎邏輯的方式?你會建議新手使用哪些工具/庫/方法(假設VS 2010 C#,.NET 4.0環境)?
僅供參考,有什麼「遺產」正在創建ASMX Web服務並使用「添加Web引用」。正如marc_s所示,你應該使用「添加服務引用」,這應該工作得很好。 – 2010-12-22 20:38:46