VC calls WebService

xiaoxiao2021-03-06  42

In the cpp file:. Void CMyTreeViewDlg :: AddMajor () {ISoapSerializerPtr Serializer; ISoapReaderPtr Reader; ISoapConnectorPtr Connector; // Connect to the service Connector.CreateInstance (__ uuidof (HttpConnector30)); Connector-> Property [ "EndPointURL"] = " Http://localhost/ws_elearning/necservices/wsjiaowu/additionalws.asmx? WSDL "; connector-> connect ();

// // // // // String // // //

// begin the message. // connector-> Property ["soapaction"] = "URI: addNumBers"; connection "] =" http://tempuri.org/earning/additionalws/listallmajorsbyObjectID "; CONNECTOR-> BeginMessage ();

// Create the soapserializer object. Serializer.createInstance (__ uuidof (soapserializer30);

// Connect The Serializer Object To The Input Stream of The Connector Object. Serializer-> INIT (_VARIANT_T ((iunknown *) connector-> inputstream);

// Build the soap message. Serializer-> Startenvelope ("soap", "," "); serializer-> startbody (" "); serializer-> startelement (" ListallmajorsbyObjectID "," http://tempuri.org/ Elearning / AdditionalWS ",", ""); Serializer-> StartElement ("ObjectID", ",", ""); serializer-> WriteString (L "11"); serializer-> endelement (); Serializer -> endelement (); serializer-> endbody (); serializer-> endenvelope (); connector-> endMESSAGE ();

Reader.createInstance (__ uuidof (SoapReader30));

Reader-> Load (_VARIANT_T ((iunknown *) connector-> outputstream), "" "

_BSTR_T RESULT = Reader-> rpcResult-> Text;

Msxml2 :: ixmldomdocumentptr pxmldom;

HRESULT HR;

Coinitialize (NULL);

hr = pXMLDom.CreateInstance (__ uuidof (DOMDocument40)); if (FAILED (hr)) {printf ( "Failed to instantiate DOMDocument40 class / n"); return;} pXMLDom-> async = VARIANT_FALSE; if (pXMLDom-> loadXML ( Result)! = variant_true) {Printf ("Failed Load XML Data from File./N%S/N", (LPCSTR) PXMLDOM-> Parseerror-> getReason ()); return;}

_bstr_t nodeName = "MAJORNAME"; _bstr_t nodeID = "MAJORID"; MSXML2 :: IXMLDOMNodeListPtr pNodeList = pXMLDom-> getElementsByTagName (nodeName); int nList = pNodeList-> length; MSXML2 :: IXMLDOMNodeListPtr pNodeValueList = pXMLDom-> getElementsByTagName (nodeID); CComboBox * combo = (CComboBox *) this-> GetDlgItem (IDC_COMBO1); for (int n = 0; n item [n]; MSXML2 :: IXMLDOMNodePtr pNodeValue = Pnodevaluelist-> item [n]; bstr_t bsnodetext = pnode-> text; // cstring * buf;

BSTR_T BSNODEVALUE = PnodeValue-> text; // buf = (cstring *) pnodeValue-> text;

BSTR BSTRVALUE = :: sysallocstring (bsnodevalue); char * buf = _com_util :: ConvertBSTRTOSTRING (BSTRVALUE);

// buf = bsnodetext; // combo-> addstring ("aaa");

// Combo-> setdlgitemtext (n 1, "111"); // cstring aaa = "231231";

Combo-> addstring (BSNodeText); Combo-> SetWindowText (BUF); Combo-> setdlgitemtext (IDC_COMBO1, BUF); // setdlgitemtext (IDC_CBO1, STR); // setItemData (INDEX, DATA [i] .value); Combo -> Setitemdata (N, (DWORD) BUF);

Combo-> setcurseel (0);

} Then modify the webservice, add the soaprpcmethod () property, indicating that the RPC call mode is used, only in this way can only be called through the method of SOAP calls in the VC, otherwise the parameter called coming in is Nothing. Public Function ListAllMajorsByObjectID (ByVal ObjectID As String) As String Dim jwfacade As New NECBusinessFacade.ELearning.JWBusinessFacade.OMGSystem Dim ds As DataSet = jwfacade. ListmajorsbyObjectIDFrommajor (ObjectId, false) Return DS.GETXML ​​() End Function

转载请注明原文地址:https://www.9cbs.com/read-72385.html

New Post(0)