工具:vc2003
1 //引入相关头文件,连接动态库,定义全局变量。 2 3 //***************************************************** 4 #include "resource.h" 5 #include "xml/Markup.h" 6 #import "msxml4.dll" 7 8 #import "C:/Program Files/Common Files/MSSoap/Binaries/mssoap30.dll" exclude("IStream", "IErrorInfo", "ISequentialStream", "_LARGE_INTEGER","_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME") 9 using namespace MSSOAPLib30; 10 using namespace std; 11 12 #include "XmlRW.h" 13 using namespace MSXML2; 14 15 _bstr_t g_strNameSpace = "urn:SmsNewOperator"; 16 //****************************************************
webservice下发短信短信实例:
BOOL WebserviceSubmit(CString g_strQXTUser,CString g_strQXTPSW,CString strMobilePhoneNumber,CString strSMSSubject,CString &strErrorMsg) { ISoapSerializerPtr Serializer; ISoapReaderPtr Reader; ISoapConnectorPtr Connector; HRESULT hr; //Connect to the service. hr = Connector.CreateInstance(__uuidof(HttpConnector30));//创建对象 if(FAILED(hr)) { printf("创建COM对象失败\n"); g_DebugMsg.Sprintf("创建COM对象失败\n"); return FALSE; } Connector->Property["EndPointURL"] ="http://211.162.125.74/ema/services/SmsNewOperator?wsdl"; //EndPointURL指定web服务 hr = Connector->Connect(); if (FAILED(hr)) { printf("创建HttpConnector30实例失败!\n"); g_DebugMsg.Sprintf("创建HttpConnector30实例失败!\n"); return FALSE; } //开始消息//消息体,// //在与服务器连接后,我们需要指定Web服务完成的操作 ,为了指定该操作,我们需要再次使用SoapConnector的Property属性 Connector->Property["SoapAction"] = "urn:SmsNewOperator/sendSms"; //函数体参数 Connector->BeginMessage(); hr = Serializer.CreateInstance(__uuidof(SoapSerializer30)); if (FAILED(hr)) { printf("创建soapSerializer失败!\n"); g_DebugMsg.Sprintf("创建soapSerializer失败!\n"); return FALSE; } Serializer->Init(_variant_t((IUnknown*)Connector->InputStream)); //Build the SOAP Message.创建soap消息 Serializer->StartEnvelope("","NONE",""); //第一个参数是命名空间。 Serializer->StartBody(""); Serializer->StartElement("sendSms",g_strNameSpace,"NONE",""); //函数处理 //第一个参数处理 Serializer->StartElement("account","","NONE",""); Serializer->WriteString((_bstr_t)g_strQXTUser); Serializer->EndElement(); //第二个参数处理 Serializer->StartElement("password","","NONE",""); Serializer->WriteString((_bstr_t)g_strQXTPSW); Serializer->EndElement(); //第三个参数处理 Serializer->StartElement("message",g_strNameSpace,"NONE",""); Serializer->StartElement("phoneNumber","","NONE",""); Serializer->WriteString((_bstr_t)strMobilePhoneNumber); Serializer->EndElement(); Serializer->StartElement("content","","NONE",""); Serializer->WriteString((_bstr_t)strSMSSubject); Serializer->EndElement(); /* Serializer->StartElement("scheduleTime","","NONE",""); Serializer->WriteString((_bstr_t)strscheduleTime); Serializer->EndElement(); */ //第三个参数处理完成 Serializer->EndElement(); //第四个参数作为返回信息 Serializer->StartElement("sendResMsg","","NONE",""); Serializer->WriteString(""); Serializer->EndElement(); //第五个参数作为返回信息 Serializer->StartElement("errMsg","","NONE",""); Serializer->WriteString(""); Serializer->EndElement(); //设置接口函数sendsms结束 Serializer->EndElement(); Serializer->EndBody(); Serializer->EndEnvelope(); Connector->EndMessage(); Reader.CreateInstance(__uuidof(SoapReader30)); Reader->Load(_variant_t((IUnknown*)Connector->OutputStream),""); //加载返回数据 // Display the result. strErrorMsg = (const char*)Reader->Body->xml; g_DebugMsg.Sprintf("Answer:%s\n\n", (const char*)Reader->Body->xml); return TRUE; }