当前位置:编程学习 > JAVA >>

C++调用java CXF服务端

 

下面是根据网络得来资料以及自己修改后代码,绝对能用

 

#include "stdafx.h"

#include <stdio.h>

#import "msxml4.dll"

using namespace MSXML2;

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

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

                    "_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")

using namespace MSSOAPLib;

void Add()

{

   ISoapSerializerPtr Serializer;

   ISoapReaderPtr Reader;

   ISoapConnectorPtr Connector;

   // 链接到服务端.

   Connector.CreateInstance(__uuidof(HttpConnector));

   Connector->Property["EndPointURL"] = "http://192.168.3.24:8080/WS_DEMO/log";

   Connector->Connect();

// 开始消息

//在与服务器连接后,我们需要指定Web服务完成的操作。

//为了指定该操作,我们需要再次使用SoapConnector的Property属性

   Connector->Property["SoapAction"] = " http://192.168.3.24:8080/WS_DEMO/log";

   Connector->BeginMessage();

   // 生成SoapSerializer对象.

   Serializer.CreateInstance(__uuidof(SoapSerializer));

   // 序列化对象连接到输入流的连接对象.

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

 

 

 

// 创建SOAP消息

Serializer->startEnvelope("","","");

 Serializer->startBody("");

// 开始SOAP消息中的一个元素,第一个参数描述了名字空间,是wsdl文件中的://targetNamespace="http://inte易做图ces.webservice.asc.com/"

// 如果它是空值,就会缺省地使用SOAP-ENV。第二、第三个参数

//调用uploadLog方法,参数名由wsdl文件决定:

   Serializer->startElement("uploadLog","http://inte易做图ces.webservice.asc.com/","STANDARD","");

   Serializer->startElement("arg0","","STANDARD","");

   Serializer->writeString("the input arg right!");

   Serializer->endElement();

   Serializer->endElement();

   Serializer->endBody();

   Serializer->endEnvelope();

   // 将该消息发送给web服务

 Connector->EndMessage();    

   // // 读取响应

   Reader.CreateInstance(__uuidof(SoapReader));

    // 将reader联接到connector的输出字符串

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

   // 显示结果

   printf("打印结果: %s\n", (const char*)Reader->RPCResult->text);

   return;

}

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

{

         CoInitialize(NULL);

   Add();

   CoUninitialize();

   return 0;

}

 

 

 

接口是:

@WebService

public inte易做图ce IClientLogService {

    /**

     * 上传日志

     * @param file

     * @return

     */

    public String uploadLog(String arg1);

}

 

实现是:

 

public class ClientLogServiceImpl implements IClientLogService{

 

    public String uploadLog(String arg) {

        // TODO Auto-generated method stub

        System.out.println("参数的值为:"+arg);

        return "参数的值为:"+arg;

    }

 

}

 

摘自cr266的专栏

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,