svc6 控制台程序利用SoapToolkit3.0调用WebService
1. 首先要安装SoapToolkit3.0安装包并安装(我的安装目录为:C:\Program Files\Common Files)
2. 新建vc控制台程序(空项目),项目名称:WinConsole6InvokeWebService,添加一个c++源文件(main.cpp)
3。main.cpp源代码
#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;
}
3>通过vs2010发布服务, 添加webservices,文件名Service.asmx,不能通过wcf发布,否则上面的代码回报错。
Service.asmx文件源码
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;
}
}
程序员的基础教程:菜鸟程序员
svc6 控制台程序利用SoapToolkit3.0调用WebService的更多相关文章
- 03server平台delphi程序不支持直接调用webservice
经过多次测试和查证,发现03server平台用delphi7.0开发的应用程序就是不支持直接调用webservice,无论这个webservice是delphi开发的还是C#开发,抑或是java开发的 ...
- 利用JavaScriptSOAPClient直接调用webService --完整的前后台配置与调用示例
JavaScriptSoapClient下载地址:https://archive.codeplex.com/?p=javascriptsoapclient JavaScriptSoapClient的D ...
- Java利用Axis远程调用WebService接口
准备工作: 主要依赖的包: 1.axis.jar 官网:http://axis.apache.org/axis/ 2.jaxrpc.jar 下载地址:http://www.java2s.com/Cod ...
- 用C#通过反射实现动态调用WebService 告别Web引用
我们都知道,调用WebService可以在工程中对WebService地址进行WEB引用,但是这确实很不方便.我想能够利用配置文件灵活调用WebService.如何实现呢? 用C#通过反射实现动态调用 ...
- 用C#通过反射实现动态调用WebService 告别Web引用(转载)
我们都知道,调用WebService可以在工程中对WebService地址进行WEB引用,但是这确实很不方便.我想能够利用配置文件灵活调用WebService.如何实现呢? 用C#通过反射实现动态调用 ...
- winform客户端程序第一次调用webservice方法很慢的解决方法
.net2.0的winform客户端最常用的与服务端通信方式是通过webservice,最近在用dottrace对客户端做性能测试的时候发现,客户端程序启动以后,第一次调用某一个webservice的 ...
- C#:控制台程序调用中间库创建窗体
1.类库项目引用System.Windows.Forms并添加引用后,才可创建窗体. 2.控制台应用程序调用中间库(DLL)中的方法创建窗体:中间类库使用反射下的Assembly加载包含窗体的类库及创 ...
- VC6.0建立控制台程序实现PDA应用
作者:iamlaosong 由于须要,又写起了文本界面的程序,以便PDA通过telnet连上运行. 假设是Linuxserver的话.这是非常easy的事,但是用户server是windows ser ...
- C++程序中调用WebService的实现
前言 因为最近的项目中需要运用到在MFC程序中调用WebService里面集成好了的函数,所以特意花了一天的时间来研究WebService的构建以及如何在MFC的程序中添加Web引用,进而来实现在C+ ...
随机推荐
- 使用Visual Studio Code搭建TypeScript开发环境
使用Visual Studio Code搭建TypeScript开发环境 1.TypeScript是干什么的 ? TypeScript是由微软Anders Hejlsberg(安德斯·海尔斯伯格,也是 ...
- Silverlight管理系统源代码(SilverlightOAFlame开发框架主要提供二次开发)
Silverlight OA系统简介 系统功能简介 l 程序界面介绍: 左侧为主菜单,主菜单可以展开和收起,主菜单下面的所有模块都可以在数据库中扩展增加,模块的权限和用户角色挂钩,可以在数据库中创建多 ...
- LeetCode "Design Tic-Tac-Toe"
We don't have to keep a complete chess board.. just counters! class TicTacToe { vector<int> cn ...
- 【转载】芯片级拆解51、AVR、MSP430、凌阳61、PIC,5种单片机,多张显微照片
先秀一张解剖照,放大裁剪,小米1S微距拍摄,800万像素摄像头很给力!今天等待被拆的是5个单片机芯片:(1)凌阳16位单片机SPCE061A ,这是我接触的第一个单片机,最高主频49MHz,32KB的 ...
- mysql高效分页方案及原理
很久以前的一次面试中,被面试官问到这个问题,由于平时用到的分页方法不多,只从索引.分表.使用子查询精准定位偏移以外,没有使用到其它方法. 后来在看其它博客看到了一些不同的方案,也一直没有整理.今天有时 ...
- Tomcat 配置 HTTPS双向认证
Tomcat 配置 HTTPS 双向认证指引说明: � 本文档仅提供 Linux 操作系统下的指引 � 在阅读本指引前请您在 Linux 部署 JDK 和 Tomcatserver为了 Tomcat ...
- sql查询当前月内的所有日期
),),)) as dt from master..spt_values where type='P' ),),),,)')
- No.5__C#
One month 今天是个有纪念意义的日子,2015-4-23.今天是实习的第一个月,算是成就达成吧.虽然,除去了周末六日和清明什么的,只剩下20多天了,但是,还是好开心 啊,毕竟是第一次参加工作, ...
- 如何在LLDB下排查message sent to deallocated instance问题
转:http://www.devdiv.com/home.php?mod=space&uid=50901&do=blog&id=50856 在XCode的以前版本中,如果遇到了 ...
- shutdown immediate时 hang住 (转载)
shutdown immediate 经常关库时hang住,在alert中有 License high water mark = 4All dispatchers and shared servers ...