SOAP XML客户端 - 使用Visual Studio 2010的C# - 怎么样? [英] SOAP xml client - using Visual Studio 2010 c# - how?

查看:117
本文介绍了SOAP XML客户端 - 使用Visual Studio 2010的C# - 怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的.NET世界,但必须使用VStudio C#2010(.NET 4.0),以产生一个请求数据从Web服务的SOAP XML方式的客户端。我搜索这里来寻找答案,但很困惑,甚至更多。 MSDN说,构建XML Web服务客户端是遗产.NET 4.0,即WSDL是旧的。使用WCF相反,他们说。 在WCF我迷路了 - 太多,太模糊。它必须是比较简单那么... 而且,我可以在网络上找到所有的例子 - 它们都使用WSDL,传统

下面是服务的我需要,以获得从所述web服务中的数据以使用定义:

要求:

  POST /catalog.asmx HTTP / 1.1
主持人:www.somewebsite.com
内容类型:text / xml的;字符集= UTF-8
内容长度:长度
SOAPAction报:https://www.somewebsite.com/KeywordSearch

< XML版本=1.0编码=UTF-8&GT?;
<肥皂:信封的xmlns:XSI =htt​​p://www.w3.org/2001/XMLSchema-instance的xmlns:XSD =htt​​p://www.w3.org/2001/XMLSchema的xmlns:肥皂= http://schemas.xmlsoap.org/soap/envelope/">
  <肥皂:身体与GT;
    < KeywordSearch的xmlns =htt​​ps://www.somewebsite.com/>
  <搜索关键词>字符串< /搜索关键词>
  < resultsReturned> INT< / resultsReturned>
   < / KeywordSearch>
  < / SOAP:身体与GT;
< /肥皂:信封>
 

响应:

  HTTP / 1.1 200 OK
内容类型:text / xml的;字符集= UTF-8
内容长度:长度

< XML版本=1.0编码=UTF-8&GT?;
<肥皂:信封的xmlns:XSI =htt​​p://www.w3.org/2001/XMLSchema-instance的xmlns:XSD =htt​​p://www.w3.org/2001/XMLSchema的xmlns:肥皂= http://schemas.xmlsoap.org/soap/envelope/">
  <肥皂:身体与GT;
    ......一些东西...
  < / SOAP:身体与GT;
< /肥皂:信封>
 

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

解决方案

如果你有一个WSDL / XSD来描述该服务,或者您可以浏览到一个URL,以获取该元数据,然后WCF与 basicHttpBinding的可能会是你最好的选择。 WSDL是肯定的没有的遗产 - 如果有什么遗产,那么它的ASP.NET/ASMX web服务

给定一个WSDL / XSD或URL,您可以连接到,只是做一个添加服务引用从Visual Studio中,你应该启动和运行致电WCF服务在任何时候 - 相信我!您不要需要知道所有的WCF只是调用一个简单的SOAP Web服务....也,与WCF 4.0,很多东西 - 尤其是配置 - 已大大改进和简化<。 / P>

至于资源适宜:还有的 MSDN WCF开发中心里面什么都有,从初学者的教程,文章和示例code。

此外,检查出屏库投了MSDN 的信息在几乎任何主题的一些真正有用的,10-15分钟块与WCF,你可能会感兴趣。

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

解决方案

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.

这篇关于SOAP XML客户端 - 使用Visual Studio 2010的C# - 怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆