3,245
社区成员
发帖
与我相关
我的任务
分享
#import "msxml4.dll"
using namespace MSXML2;
#import "C:\Program Files\Common Files\MSSoap\Binaries\MSSOAP30.dll" \
exclude("IStream", "ISequentialStream", "_LARGE_INTEGER", \
"_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")
using namespace MSSOAPLib30;
void CallService()
{
try{
ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;
// Connect to the service
if(FAILED(Connector.CreateInstance(__uuidof(HttpConnector30)))){
AfxMessageBox("Create HTTP Connector Failed!");
return;
}
//Connector->Property["EndPointURL"] = "http://www.soyoyo.cn/WebService/SoyoyoService.asmx?WSDL";
Connector->Property["EndPointURL"] = "http://phs.cnool.net/webserver/spserver_ordersend.asmx";
Connector->Connect();
// Begin message
//Connector->Property["SoapAction"] = "http://tempuri.org/GetFreeSendRemain";
Connector->Property["SoapAction"] = "http://tempuri.org/ordersend";
Connector->BeginMessage();
// Create the SoapSerializer
if(FAILED(Serializer.CreateInstance(__uuidof(SoapSerializer30)))){
AfxMessageBox("Create SOAP Serializer Failed!");
return;
}
// Connect the serializer to the input stream of the connector
Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));
// Build the SOAP Message
Serializer->StartEnvelope("","","");
Serializer->StartBody("");
//Serializer->StartElement("GetFreeSendRemain","http://tempuri.org/","","");
// Serializer->StartElement("ordersend","http://tempuri.org/","","");
// Serializer->StartElement("UserName","","","");
// Serializer->WriteString("krh2001");
// Serializer->EndElement();
// Serializer->StartElement("Password","","","");
// Serializer->WriteString("kong2000");
// Serializer->EndElement();
// Serializer->StartElement("username","", "","");
// Serializer->WriteString("nhgame");
// Serializer->EndElement();
// Serializer->StartElement("content","", "","");
// Serializer->WriteString("你的初始密码为:s89R4x37。请保管好自己的密码。");
// Serializer->EndElement();
// Serializer->StartElement("destpohne","", "","");
// Serializer->WriteString("057466511283");
// Serializer->EndElement();
// Serializer->StartElement("shortcode","", "","");
// Serializer->WriteString("61");
// Serializer->EndElement();
// Serializer->StartElement("servicecode","", "","");
// Serializer->WriteString("f010");
// Serializer->EndElement();
//
// Serializer->EndElement();
char buf[4096];
sprintf(buf, c_xml, "你的初始密码为:s89R4x37。请保管好自己的密码。", "057466511283");
Serializer->WriteXml(buf);
Serializer->EndBody();
Serializer->EndEnvelope();
// Send the message to the web service
Connector->EndMessage();
// Let us read the response
if(FAILED(Reader.CreateInstance(__uuidof(SoapReader30)))){
AfxMessageBox("Create SOAP Reader Failed!");
return;
}
// Connect the reader to the output stream of the connector
Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");
// Display the result
// char buf[4096];
try{
IXMLDOMElementPtr elm = Reader->RpcResult;
if(elm->hasChildNodes ())
{
IXMLDOMNodeListPtr nodes = elm->childNodes;
for(int i = 0; i < nodes->length; ++i)
{
sprintf(buf, "%s = %s", (const char*) nodes->item[i]->nodeName,
(const char*)nodes->item[i]->text);
AfxMessageBox(buf);
}
}
// while(elm){
// sprintf(buf, "Answer: \n%s\n", (const char *)elm->xml);
// AfxMessageBox(buf);
// elm = elm->nextSibling;
/// sprintf(buf, "Answer: %s\n", (const char *)Reader->RpcResult->nextSibling->nextSibling->xml);
// AfxMessageBox(buf);
// }
}
catch(_com_error& ce)
{
CString str;
str.Format("COM Error :(%08X)%s", ce.Error(), ce.ErrorMessage());
AfxMessageBox(str);
}
}
catch(_com_error& ce)
{
CString str;
str.Format("COM Error :(%08X)%s", ce.Error(), ce.ErrorMessage());
AfxMessageBox(str);
return;
}
}