下面是根據網絡得來資料以及自己修改後代碼,絕對能用
#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://interfaces.webservice.asc.com/"
// 如果它是空值,就會缺省地使用SOAP-ENV。第二、第三個參數
//調用uploadLog方法,參數名由wsdl文件決定:
Serializer->startElement("uploadLog","http://interfaces.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 interface 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的專欄