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+ ...
随机推荐
- Java 使用Redis缓存工具的图文详细方法
开始在 Java 中使用 Redis 前, 我们需要确保已经安装了 redis 服务及 Java redis 驱动,且你的机器上能正常使用 Java. (1)Java的安装配置可以参考我们的 Java ...
- Office web app server2013详细的安装和部署
转自:http://blog.csdn.net/u011355311/article/details/9360293 SharePoint 2013集成Office web apps server20 ...
- PHP DES 加解密
代码很简单,如下: <?php $key = 'very important data'; function jiami($key, $str) { /* Open module, and cr ...
- ruby中http请求方法整理
#POST请求 请求包是json包 返回body并转换成json对象def post_json *args uri = URI.parse args[0] req = Net::HTTP::Post. ...
- C#微信json结构接收参数 转载
http://blog.csdn.net/u010773333/article/details/48524155 发素材的时间要上传资源故此要用json格式数据,需要转化. 微信服务器交互基本上都是j ...
- Code Igniter + PHP5.3 + SqlServer2008配置
1.配置apache+php5.3 2.配置sql server服务器,并允许远程连接. 3.去http://www.microsoft.com/en-us/download/details.aspx ...
- Spring Boot 性能优化
spring 框架给企业软件开发者提供了常见问题的通用解决方案,包括那些在未来开发中没有意识到的问题.但是,它构建的 J2EE 项目变得越来越臃肿,逐渐被 Spring Boot 所替代.Spring ...
- Bootstrap之BootstrapDialog
Make use of Bootstrap's modal more monkey-friendly. 参考地址:http://nakupanda.github.io/bootstrap3-dialo ...
- NGUI之渲染DrawCall的合并
在Unity中,每次引擎准备数据并通知GPU的过程称为一次Draw Call.Draw Call值越低,会得到更好的渲染性能. (NGUI 查看DrawCall工具(NGUI-OPEN-Draw Ca ...
- django model 中class meta
class Meta: ordering = ['-num', 'length'] verbose_name = 'name' verbose_name_plural = 'names' orderi ...