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

发布于 2024-10-08 20:11:24 字数 1462 浏览 0 评论 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>

响应:

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 环境)?

I'm new to .NET world, yet have to use VStudio C# 2010 (.NET 4.0) to produce a client that requests data from a web service in SOAP Xml fashion. I've searched here for answers but got confused even more. MSDN says that "Building XML Web Service Clients" is legacy for .NET 4.0, i.e. WSDL is legacy. Use "WCF" instead, they say.
In WCF i got lost - too much and too vague. It must be simpler then that...
And all examples that i could find on the web - they all use WSDL, "the legacy".

Here are the definitions of the service i need to use in order to obtain the data from the web service:

request:

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>

Response:

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>

So, what is the right, or at least most logical way to built this simple client? What tools/libraries/methodologies would you suggest to newbie (assuming VS 2010 C#, .NET 4.0 environment)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月依秋水 2024-10-15 20:11:24

如果您有 WSDL/XSD 来描述该服务,或者您可以导航到 URL 来获取该元数据,那么带有 basicHttpBinding 的 WCF 可能是您的最佳选择。 WSDL 绝对不是“遗留” - 如果有什么是遗留的,那么它就是 ASP.NET/ASMX Web 服务。

给定一个可连接到的 WSDL/XSD 或 URL,只需在 Visual Studio 中执行添加服务引用,您就应该立即启动并运行调用您的 WCF 服务 - 相信我!您不需要了解 WCF 的全部内容,只需调用一个简单的 SOAP Web 服务...而且,在 WCF 4.0 中,许多内容(尤其是配置)都得到了极大的改进和简化。

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

另外,请查看MSDN 上的屏幕投射库以获取一些信息非常有用的 10-15 分钟的信息块,涉及您可能感兴趣的与 WCF 相关的任何主题。

If you have a WSDL/XSD to describe that service, or if you can navigate to an URL to grab that metadata, then WCF with basicHttpBinding would probably be your best bet. WSDL is definitely not "legacy" - if anything is legacy, then it's ASP.NET/ASMX webservices.

Given a WSDL/XSD or a URL where you can connect to, just do an Add Service Reference from within Visual Studio, and you should be up and running calling your WCF service in no time - trust me! You don't need to know all of WCF just to call a simple SOAP web service.... also, with WCF 4.0, lots of things - especially configuration - have been vastly improved and simplified.

As for resoures: there's the MSDN WCF Developer Center which has everything from beginner's tutorials to articles and sample code.

Also, check out the screen cast library up on MSDN for some really useful, 10-15 minute chunks of information on just about any topic related to WCF you might be interested in.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文