java做的一个WEBSERVICE,上面有一个接口,返回的是一个类的对象,请问如何在VC6里调用这个接口,并得到这个对象呢?

解决方案 »

  1.   

    #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;
    }
    }
      

  2.   

    谢谢!
    还有一个问题:
    调用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>这样的话我要怎么做呢?