C++调用Java++web+service帮助文档文档格式.docx
- 文档编号:20199300
- 上传时间:2023-01-17
- 格式:DOCX
- 页数:10
- 大小:101.51KB
C++调用Java++web+service帮助文档文档格式.docx
《C++调用Java++web+service帮助文档文档格式.docx》由会员分享,可在线阅读,更多相关《C++调用Java++web+service帮助文档文档格式.docx(10页珍藏版)》请在冰豆网上搜索。
mssoaptookit必须是3.0,否则会出现错误。
默认安装好mssouptookit3.0後,就可以使用C+来调用webservice了。
这时候可以使用mssoaptookit3.0来监控C+的soap请求。
现在假设网络上有一个webservice:
/192.168.0.10:
8082/ServiceGateway/ServiceServer,下面就这个webservice来详细描述使用mssoaptookit3.0来监控C+调用webservice的情形和不监控的情形,2.2使用使用mssoaptookit3.0监视监视C+调用调用webservice要想使用mssoaptookit3.0来监控,首先请打开TraceUtility。
打开时候请新建一个FormattedTrace,如下图这时候会弹出一个如下图的窗口:
Localport,可以自己定义,使用本机上的一个空闲的端口即可,本例设置为:
8080,该端口的意义:
以后使用该端口来发送soap请求,Destination:
localhos中的localhost请设置为webservice的IP,本例应该设置为:
192.168.0.10,Destination:
80请设置为webservice的端口,本例设置为:
8082,设置好之后就可以通过localport来监控soap请求了。
先查看wsdl文件:
8082/ServiceGateway/ServiceServer?
wsdl-可见有两个远程方法:
intnumList(int,int)Stringlogin(String)用vc建立一个console的程序,其全部代码如下:
/testwebservice.cpp:
Definestheentrypointfortheconsoleapplication./#includestdafx.h#include#importmsxml4.dllusingnamespaceMSXML2;
#importC:
ProgramFilesCommonFilesMSSoapBinariesmssoap30.dllexclude(IStream,IErrorInfo,ISequentialStream,_LARGE_INTEGER,_ULARGE_INTEGER,tagSTATSTG,_FILETIME)usingnamespaceMSSOAPLib30;
voidAdd()ISoapSerializerPtrSerializer;
ISoapReaderPtrReader;
ISoapConnectorPtrConnector;
/Connecttotheservice.Connector.CreateInstance(_uuidof(HttpConnector30);
/使用EndPointURL属性指定Web服务,因为使用soaptookit3.0来监控,所以使用本地的8080端口来发送soap请求Connector-PropertyEndPointURL=http:
/localhost:
8080/ServiceGateway/ServiceServer;
/这是不使用mssoaptookit3.0来监控的情形,需要直接发送请求到远端的端口。
/Connector-PropertyEndPointURL=http:
8082/ServiceGateway/ServiceServer;
Connector-Connect();
/开始消息/在与服务器连接后,我们需要指定Web服务完成的操作。
/为了指定该操作,我们需要再次使用SoapConnector的Property属性Connector-PropertySoapAction=http:
/这是不使用mssoaptookit3.0来监控的情形/Connector-PropertySoapAction=http:
Connector-BeginMessage();
/CreatetheSoapSerializerobject.Serializer.CreateInstance(_uuidof(SoapSerializer30);
/Connecttheserializerobjecttotheinputstreamoftheconnectorobject.Serializer-Init(_variant_t(IUnknown*)Connector-InputStream);
/创建SOAP消息Serializer-StartEnvelope(,);
Serializer-StartBody(“”);
/开始SOAP消息中的一个元素,第一个参数描述了名字空间,是wsdl文件中的:
/targetNamespace=http:
/gateway/如果它是空值,就会缺省地使用SOAP-ENV。
第二、第三个参数/调用login方法,参数名由wsdl文件决定:
/Serializer-StartElement(login,http:
/server.hw/,STANDARD,);
Serializer-StartElement(arg0,STANDARD,);
Serializer-WriteString(cellcom);
Serializer-EndElement();
Serializer-EndBody();
Serializer-EndEnvelope();
/将该消息发送给web服务Connector-EndMessage();
/读取响应.Reader.CreateInstance(_uuidof(SoapReader30);
/将reader联接到connector的输出字符串Reader-Load(_variant_t(IUnknown*)Connector-OutputStream),);
/显示结果printf(Answer:
%sn,(constchar*)Reader-RpcResult-text);
return;
intmain(intargc,char*argv)CoInitialize(NULL);
Add();
CoUninitialize();
return0;
上面的代码是一个完整的C+调用webservice的情形,运行之后会发现TraceUtility里有些信息,如下图:
第一个框里是一个soap请求,第二个框是soap请求返回的结果。
2.3不使用不使用mssoaptookit3.0监视监视C+调用调用webservice不使用mssoaptookit3.0监控的时候,C+的代码要做如下修改:
/使用EndPointURL属性指定Web服务,因为使用soaptookit3.0来监控,所以使用本地的8080端口来发送soap请求/Connector-PropertyEndPointURL=http:
Connector-PropertyEndPointURL=http:
/为了指定该操作,我们需要再次使用SoapConnector的Property属性/Connector-PropertySoapAction=http:
/这是不使用mssoaptookit3.0来监控的情形Connector-PropertySoapAction=http:
/要使用http:
8082/ServiceGateway/ServiceServer来指定服务。
/其他的基本上没改变。
2.4被调用的方法参数是数组的情形被调用的方法参数是数组的情形下面是调用numList的情形,通过查看wsdl知道,numList有两个参数:
-通过询问webservice的开发人员知道,第一个参数是int,第二个参数是int,该方法是把int里所有在第一参数之前的数加一,Serializer-StartEnvelope(,);
Serializer-StartBody();
/开始SOAP消息中的一个元素,第一个参数描述了名字空间,/如果它是空值,就会缺省地使用SOAP-ENV。
第二、第三个参数Serializer-StartElement(numList,http:
/gateway/,STANDARD,);
Serializer-WriteString
(2);
Serializer-StartElement(arg1,STANDARD,);
Serializer-WriteString(53);
Serializer-WriteString(58);
查看soap监控里的信息:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 调用 Java web service 帮助 文档