VC6如何使用MS SOAP TOOLKIT java做的一个WEBSERVICE,上面有一个接口,返回的是一个类的对象,请问如何在VC6里调用这个接口,并得到这个对象呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 #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; }} 谢谢!还有一个问题:调用web service后返回的信息是被序列化了的如:<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><getItemResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><getItemReturn href="#id0"/></getItemResponse><multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns1:ContItem" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://d.contract.i.cqrk.com"><contId href="#id1"/><contTel xsi:type="xsd:string">70709518</contTel><contName xsi:type="xsd:string">51020</contName></multiRef></soapenv:Body></soapenv:Envelope>这样的话我要怎么做呢? CFileDialog 实时(内部代码)修改文件类型 格式转换问题 VB写的COM组件,在VC中如何调用。 高难度问题,如何压缩一个视音频流(directshow) ???? 用计算机发送短信息有几种方法,先谢谢大家了。 弹出窗口与普通窗口的区别。 能说一说控件的编写原理吗? 可以介绍一下关于文件的存储的知识吗 真正的菜鸟问题:用户在Edit框输入内容后,程序如何获取Edit框的内容!请给出实现细节,给100分! 使用VC连接数据库时,设置连接时间有什么用? 在编辑框中如何分行显示? 计时器问题
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;
}
}
还有一个问题:
调用web service后返回的信息是被序列化了的如:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getItemResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<getItemReturn href="#id0"/>
</getItemResponse>
<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns1:ContItem" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://d.contract.i.cqrk.com">
<contId href="#id1"/>
<contTel xsi:type="xsd:string">70709518</contTel>
<contName xsi:type="xsd:string">51020</contName>
</multiRef>
</soapenv:Body></soapenv:Envelope>这样的话我要怎么做呢?