SOAP xml客户端 - 使用Visual Studio 2010 c# - 如何?

rit*_*ita 6 c# wcf soap .net-4.0

我是.NET世界的新手,但必须使用VStudio C#2010(.NET 4.0)来生成以SOAP Xml方式从Web服务请求数据的客户端.我在这里寻找答案,但更加困惑.MSDN表示"构建XML Web服务客户端"是.NET 4.0的遗产,即WSDL是遗留的.他们说,使用"WCF".在WCF我迷路了 - 太多太模糊了.它必须更简单......以及我可以在网上找到的所有例子 - 它们都使用WSDL,"遗产".

以下是为了从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>
Run Code Online (Sandbox Code Playgroud)

响应:

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>
Run Code Online (Sandbox Code Playgroud)

那么,构建这个简单客户端的正确方法,或者至少是最合理的方式是什么?您会向新手建议哪些工具/库/方法(假设是VS 2010 C#,.NET 4.0环境)?

mar*_*c_s 5

如果您有一个WSDL/XSD来描述该服务,或者您可以导航到一个URL来获取该元数据,那么WCF basicHttpBinding可能是您最好的选择.WSDL绝对不是 "遗留" - 如果有任何遗产,那么它就是ASP.NET/ASMX webservices.

给定一个WSDL/XSD或您可以连接到的URL,只需Add Service Reference在Visual Studio中执行,您就应该立即启动并运行调用您的WCF服务 - 相信我!你并不需要了解所有WCF的只是调用一个简单的SOAP Web服务....还与WCF 4.0,很多东西-尤其是配置-已大大改进和简化.

至于资源:MSDN WCF开发人员中心提供从初学者教程到文章和示例代码的所有内容.

另外,请查看MSDN上屏幕强制转换库,了解一些非常有用的10-15分钟信息块,其中包含与您可能感兴趣的WCF相关的任何主题.