VC++ 调用java 编写的webService
VC++ 调用java 编写的webService
Java 端编写的WebService 程序略。
java 端WebService 路径 : http://localhost:8080/Axis2WSTest/services/Converte
java 端 SoapAction urn:sayHello
public void sayHello(String userName, String message){System.err.println("Hello!" + userName + " and he said: " + message);}
#import "msxml4.dll" #import "C:\Program Files\Common Files\MSSoap\Binaries\mssoap30.dll" \ exclude("IStream", "IErrorInfo", "ISequentialStream", "_LARGE_INTEGER", \ "_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")using namespace MSSOAPLib30;
ISoapConnectorPtr connector; Connector.CreateInstance(__uuidof(HttpConnector30));
Connector->Property ["EndPointURL"] = "http://localhost:8080/Axis2WSTest/services/Converte";
Connector->Connect();
Connector->Property ["SoapAction"] = "urn:sayHello";
必需在SoapSerializer(消息准备函数)之前先启动消息处理机制 Connector->BeginMessage(); 在消息处理完毕之后,用EndMessage()函数将消息送往服务器。 . . [ 消息准备代码 ] . . Connector->EndMessage();
// 创建SoapSerializer对象,并用InputSTream进行初始化。 ISoapSerializerPtr Serializer; Serializer.CreateInstance(_uuidof(SoapSerializer30)); Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));
<SOAP: Envelope xmlns:SOAP="soap namespace"> <SOAP:Body> <m:someMethodName xmlns:m="some namespace"> <someParameter> someParameterValue </someParameter> <m:someMethodName> </SOAP:Body> </SOAP: Envelope>
Serializer->startEnvelope("","",""); // 开始处理SOAP消息。第一个参数是命名空间,缺省为SOAP-ENV。 // 第二个参数定义URI。第三个参数定义Serialzier->startBody("")函数的编码方式。 // 开始处理<Body>元素,第一个参数是URI的编码类型,缺省为NONE。 Serializer->StartBody("");Serializer->StartElement("sayHello","http://wtp","","m"); // 开始处理Body里的子元素。 // 第一个参数是元素名。第二个参数是URI。 // 第三个参数编码类型。第四个参数是元素的命名空间。Serializer->StartElement("userName","","","");Serializer->WriteString("laghari78");// 写入元素值Serializer->EndElement();Serializer->StartElement("message","","","");Serializer->WriteString("i say something");// 写入元素值Serializer->EndElement();Serializer->EndElement();Serializer->EndBody();Serializer->EndEnvelope(); 在上面的每个startXXX函数后都要又相应的endXXX函数来结尾。消息做完之后,连接器就调用endMessage()方法将消息发送到服务器。