vc6控制台程序利用SoapToolkit3.0调用WebService

原文地址::https://www.cnblogs.com/joeblackzqq/p/1961818.html

 

相关文章

1、使用Visual C++开发SOAP客户端应用----https://www.cnblogs.com/dengpeng1004/p/3502440.html

2、VC++使用Soap ToolKit3.0调用WebService接口----https://blog.csdn.net/shixin_0125/article/details/42493535?locationNum=13&fps=1

3、VC++6.0访问webservice----https://blog.csdn.net/aasmfox/article/details/51939256

4、使用C++开发webservice客户端(上)----https://blog.csdn.net/iteye_5681/article/details/81795416

5、使用C++开发webservice客户端(下)----https://blog.csdn.net/iteye_5681/article/details/81795418

 

vc6控制台程序利用SoapToolkit3.0调用WebService

1. 首先要安装SoapToolkit3.0安装包并安装(我的安装目录为:D:\Program Files\MSSOAP\)

2. 新建vc控制台程序(空项目),项目名称:WinConsole6InvokeWebService,添加一个c++源文件(main.cpp),将SOAP安装目录下的lib文件D:\Program Files\MSSOAP\Lib\mssoap30.lib复制到项目文件夹下。

3。添加源代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

#include <stdio.h>

#include <iostream>

#include <vector>

 

#import "msxml4.dll"

 

using namespace std;

using namespace MSXML2;

 

#import "C:\Program Files\Common Files\MSSoap\Binaries\MSSOAP30.dll" \

        exclude("IStream""IErrorInfo""ISequentialStream""_LARGE_INTEGER", \

        "_ULARGE_INTEGER""tagSTATSTG""_FILETIME")

 

using namespace MSSOAPLib30;

 

void query(char* EndPointURL, char* Namespace, char* method, vector<string>& v)

{

    ISoapSerializerPtr Serializer;

    ISoapReaderPtr Reader;

    ISoapConnectorPtr Connector;

     

    // Connect to the service

    Connector.CreateInstance(__uuidof(HttpConnector30));

    Connector->Property["EndPointURL"] = EndPointURL;        // 接口位置

    Connector->Connect();                                    // 和服务器连接

     

    // Begin message

    Connector->Property["SoapAction"] = _bstr_t(Namespace) + _bstr_t(method);

    Connector->BeginMessage();

 

    Serializer.CreateInstance(__uuidof(SoapSerializer30));

 

    // 将serializer连接到connector的输入字符串

    Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));

 

    // 创建SOAP消息

    Serializer->StartEnvelope("soap""""");

    Serializer->StartBody("body");

    Serializer->StartElement(method, Namespace, """"); // 命名空间必须有

 

    for(vector<string>::iterator it = v.begin(); it != v.end(); it++)

    {

        Serializer->StartElement("username", Namespace, """");

        Serializer->WriteString(it->c_str());

        Serializer->EndElement();

    }

 

    Serializer->EndElement();

 

    Serializer->EndBody();

    Serializer->EndEnvelope();

 

    Connector->EndMessage();             // Send the message to the web service

 

    // 读取响应

    Reader.CreateInstance(__uuidof(SoapReader30));

    Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");

 

    printf("Answer: %s\n", (const char*)Reader->RpcResult->text); // Reader->RpcResult->Gettext()等效

}

 

int main(int argc, char* argv[])

{

    CoInitialize(NULL);

    char* EndPointURL = "http://192.168.0.100/WebService1/Service.asmx";

    char* Namespace = "http://tempuri.org/";

 

    vector<string> v1, v2;

 

    v2.push_back("JoeBlack");

    query(EndPointURL, Namespace, "Hello", v2);

 

    CoUninitialize();

    getchar();

 

    return 0;

}

这样,程序就完成了,运行起来就可以得到WebService的服务了。

其中的WebService服务是用ASP.NET2005(C#)开发的,源码如下:

using System;

using System.Web;

using System.Web.Services;

using System.Web.Services.Protocols;

 

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class Service : System.Web.Services.WebService

{

    public Service () {

 

        //如果使用设计的组件,请取消注释以下行

        //InitializeComponent();

    }

 

    [WebMethod(Description = "Let's say \"Hi\"")]

    public string Hi()

    {

        return "Hello World, Happy New Year!";

    }

 

    [WebMethod(Description = "Hello JoeBlack")]

    public string Hello(string username)

    {

        return username + ", Happy New Year!";

    }

 

    [WebMethod(Description = "求和的方法")]

    public double addition(double i, double j)

    {

        return i + j;

    }

 

    [WebMethod(Description = "求差的方法")]

    public double subtract(double i, double j)

    {

        return i - j;

    }

 

    [WebMethod(Description = "求积的方法")]

    public double multiply(double i, double j)

    {

        return i * j;

    }

 

    [WebMethod(Description = "求商的方法")]

    public double division(double i, double j)

    {

        if (j != 0)

            return i / j;

        else

            return 0;

    }

}

调用的Hello方法,其调用方式如下:

SOAP 1.1

以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

POST /WebService1/Service.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Hello"

<?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>
    <Hello xmlns="http://tempuri.org/">
      <username>string</username>
    </Hello>
  </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>
    <HelloResponse xmlns="http://tempuri.org/">
      <HelloResult>string</HelloResult>
    </HelloResponse>
  </soap:Body>
</soap:Envelope>

SOAP 1.2

以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

POST /WebService1/Service.asmx HTTP/1.1
Host: localhost
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <Hello xmlns="http://tempuri.org/">
      <username>string</username>
    </Hello>
  </soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <HelloResponse xmlns="http://tempuri.org/">
      <HelloResult>string</HelloResult>
    </HelloResponse>
  </soap12:Body>
</soap12:Envelope>

HTTP POST

以下是 HTTP POST 请求和响应示例。所显示的占位符需替换为实际值。

POST /WebService1/Service.asmx/Hello HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length

username=string
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">string</string>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: Soap Toolkit 3.0 是一个用于在各种平台上构建和部署 Web 服务的工具集。它提供了一种简单且可扩展的方式来创建和使用 Web 服务,能够帮助开发者轻松地构建跨平台的分布式应用程序。 在 CSDN(中国最大的开发者社区)上,可以找到并下载 Soap Toolkit 3.0。CSDN提供了一个集成的开发者平台,为开发人员提供了软件、代码和技术文章等资源。CSDN的下载中心是一个开放的资源平台,提供各种开发工具和库,开发者可以在这里搜索并下载自己需要的软件。 要下载 Soap Toolkit 3.0,你可以在CSDN的搜索框中输入关键词 "Soap Toolkit 3.0" 并点击搜索按钮。结果页面将显示与Soap Toolkit 3.0相关的文章、下载链接和相关资源。选择合适的链接,进入下载页面,按照指示完成下载过程。这样,你就可以在本地计算机上获得 Soap Toolkit 3.0 的安装文件,并按照指南进行安装和配置。 下载 Soap Toolkit 3.0 后,你可以使用它来开发和部署 Web 服务。它支持 SOAP(Simple Object Access Protocol)协议,使得不同平台之间的应用程序可以通过 Web 服务进行通信。Soap Toolkit 3.0 提供了多种编程语言的支持,例如 C++、Java、VBScript 等,使得开发者可以使用自己熟悉的语言来开发 Web 服务。 总之,通过在CSDN上下载和使用 Soap Toolkit 3.0,开发者可以方便地构建和部署跨平台的 Web 服务应用程序。CSDN作为一个技术交流平台,为开发者们提供了丰富的资源,使得他们可以更加轻松地获取他们需要的技术工具和知识。 ### 回答2: 要在CSDN上下载Soap Toolkit 3.0,您可以按照以下步骤进行操作: 1. 打开浏览器,并在地址栏中输入“www.csdn.net”以访问CSDN网站主页。 2. 在网站主页的搜索栏中输入“Soap Toolkit 3.0”并点击搜索按钮。 3. 在搜索结果页面中,您可以看到与Soap Toolkit 3.0相关的文章、教程和下载链接。 4. 点击其中一个下载链接来访问Soap Toolkit 3.0的下载页面。 5. 在下载页面中,您可能需要先登录您的CSDN账户。如果您没有账户,可以选择注册一个新账户。 6. 在下载页面中,您可以看到有关Soap Toolkit 3.0的详细信息,例如版本、文件大小和发布日期。 7. 点击下载按钮或链接,将开始下载Soap Toolkit 3.0的安装文件。 8. 选择保存安装文件的目标文件夹,并等待下载完成。 9. 下载完成后,您可以通过点击安装文件来开始安装Soap Toolkit 3.0。 10. 按照安装向导的提示,完成Soap Toolkit 3.0的安装过程。 11. 安装完成后,您就可以在您的计算机上使用Soap Toolkit 3.0进行开发和集成相关工作了。 请注意,以上步骤仅为参考,具体步骤可能会根据CSDN网站的更新和变化而稍有不同。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值