Webservice series teaching (14)-How to call webservice (vc5)

Source: Internet
Author: User
//////////////////////////////////////// //////////////////////////////////////// //////////////////
// Function: CMClientDlg: OnDeleteitemListparam ()
//
// Parameters: (NMHDR * pNMHDR, LRESULT * pResult)
//
// Description: for each row of list, it callthe Release
//
// Returns: void
//
//////////////////////////////////////// //////////////////////////////////////// //////////////////
Void CMClientDlg: OnDeleteitemListparam (NMHDR * pNMHDR, LRESULT * pResult)
{
// We have to release lParam that I filled with object of ISoapMapper
NMLISTVIEW * tempVar = (NMLISTVIEW *) pNMHDR ;;

If (reinterpret_cast <IUnknown *> (tempVar-> lParam ))
(Reinterpret_cast <IUnknown *> (tempVar-> lParam)-> Release ();

* PResult = 0;
}

//////////////////////////////////////// //////////////////////////////////////// //////////////////
// Function: CMClientDlg: OnDeleteitemTree ()
//
// Parameters: (NMHDR * pNMHDR, LRESULT * pResult)
//
// Description: for each tree elements, it callthe Release method
// Returns: void
//
//////////////////////////////////////// //////////////////////////////////////// //////////////////
Void CMClientDlg: OnDeleteitemTree (NMHDR * pNMHDR, LRESULT * pResult)
{
// We have to release lParam that I filled with object
NMTREEVIEW * tempVar = (NMTREEVIEW *) pNMHDR ;;
If (reinterpret_cast <IUnknown *> (tempVar-> itemOld. lParam ))
(Reinterpret_cast <IUnknown *> (tempVar-> itemOld. lParam)-> Release ();

* PResult = 0;
}

//////////////////////////////////////// //////////////////////////////////////// //////////////////
// Function: CMClientDlg: OnSelchangedTree ()
//
// Parameters: (NMHDR * pNMHDR, LRESULT * pResult)
//
// Description: for selection on tree, it updates the list
//
// Returns: void
//
//////////////////////////////////////// //////////////////////////////////////// //////////////////
Void CMClientDlg: OnSelchangedTree (NMHDR * pNMHDR, LRESULT * pResult)
{
// If the selected is operation, update the list with its parameters
NMTREEVIEW * pNMTreeView = (NMTREEVIEW *) pNMHDR;

IUnknown * pUnk = reinterpret_cast <IUnknown *> (pNMTreeView-> itemNew. lParam );

If (! PUnk)
Return;

IWSDLOperation * pOper = 0;

M_strParameter.Empty ();
UpdateData (false );

If (SUCCEEDED (pUnk-> QueryInterface (_ uuidof (IWSDLOperation), reinterpret_cast <void **> (& pOper ))))
{
If (UpdateList ()! = 1)
MSG ("Parameter list can not be created! ");
}

* PResult = 0;

Cleanup:
If (pOper)
POper-> Release ();

Return;
}
//////////////////////////////////////// //////////////////////////////////////// /////////////////////////
// Function: CMClientDlg: OnLoad ()
//
// Parameters: No Parameters
//
// Description: takes the service, ports and operations and fills the tree
//
// Returns: void
//
//////////////////////////////////////// //////////////////////////////////////// /////////////////////////
Void CMClientDlg: OnLoad ()
{
USES_CONVERSION;

UpdateData (true );
// Chech if wsdl file is given, if not, return
If (CheckforURL () =-1)
Return;

// Delete the tree if exist, if a tree exist and cant be deleted, return
If (! DestroyTree ())
Return;

HRESULT hr = S_ OK;

BSTR bstrWSDLFileName = 0;
BSTR bstrServiceName = 0;
BSTR bstrPortName = 0;
BSTR bstrOperationName = 0;
Int flag = 1;

Int flag_SERVICE = 0;
Int flag_PORT = 0;
Int flag_OPERATION = 0;

CComPtr <IEnumWSDLService> pIEnumWSDLServices;
CComPtr <IEnumWSDLPorts> pIEnumWSDLPorts;
CComPtr <IEnumWSDLOperations> pIEnumWSDLOps;
CComPtr <IWSDLOperation> pIOperation;
CComPtr <IWSDLReader> pIWSDLReader;
CComPtr <IWSDLService> pIWSDLService;
CComPtr <IWSDLPort> pIWSDLPort;

Long cFetched;

HTREEITEM hSERVICE;
HTREEITEM hPORT;
HTREEITEM hOPERATION;

// Take the name of wsdl file
BstrWSDLFileName = m_strURL.AllocSysString ();

If (bstrWSDLFileName = NULL)
Return;

Hr = CoCreateInstance (_ uuidof (WSDLReader), NULL, CLSCTX_INPROC_SERVER, _ uuidof (IWSDLReader ),
(Void **) & pIWSDLReader );
CHECK_HRESULT (hr, "Can not create the object of the CLSID_WSDLReader ");

// Loading needs wsdl and wsml files, but I dont know wsml file and I pass ""
Hr = pIWSDLReader-> Load (bstrWSDLFileName, L "");
CHECK_HRESULT (hr, "Loading WSDL and WSML files failed! ");

// Get soap service
Hr = pIWSDLReader-> GetSoapServices (& pIEnumWSDLServices );
CHECK_HRESULT (hr, "Can not get Services ");

If (! PIEnumWSDLServices)
MSG ("Can not get Services ");

While (hr = pIEnumWSDLServices-> Next (1, & pIWSDLService, & cFetched) = S_ OK)
{
// At least one time this loop shoshould go inside; if it does not, the flag wont be updated
// So we can not continue and shoshould destroy the tree if any part created
Flag_SERVICE = 1;
// Get service name
Hr = pIWSDLService-> get_name (& bstrServiceName );
CHECK_HRESULT (hr, "Can not get Service names ");

// Add the name of service in to tree
// First field is NULL, it means insert this as root
HSERVICE = AddtoTree (NULL, TVI_SORT, W2A (bstrServiceName), TVIF_TEXT, pIWSDLService );
: SysFreeString (bstrServiceName );
If (! HSERVICE)
{
Flag = 0;
Goto cleanup;
}

Hr = pIWSDLService-> GetSoapPorts (& pIEnumWSDLPorts );
CHECK_HRESULT (hr, "Can not get Ports ");

If (! PIEnumWSDLPorts)
MSG ("Can not get Ports ");

While (hr = pIEnumWSDLPorts-> Next (1, & pIWSDLPort, & cFetched) = S_ OK)
{
// At least one time this loop shoshould go inside; if it does not, the flag wont be updated
// So we can not continue and shoshould destroy the tree if any part created
Flag_PORT = 1;
// Get port name
Hr = pIWSDLPort-> get_name (& bstrPortName );
CHECK_HRESULT (hr, "Can not get Port names ");

// Add to tree but as a child of SERVICE
HPORT = AddtoTree (hSERVICE, TVI_SORT, W2A (bstrPortName), TVIF_TEXT, pIWSDLPort );
: SysFreeString (bstrPortName );
If (! HPORT)
{
Flag = 0;
Goto cleanup;
}

Hr = pIWSDLPort-> GetSoapOperations (& pIEnumWSDLOps );
CHECK_HRESULT (hr, "Can not get Operations ");
If (! PIEnumWSDLOps)
MSG ("Can not get Operations ");

While (hr = pIEnumWSDLOps-> Next (1, & pIOperation, & cFetched) = S_ OK)
{
// At least one time this loop shoshould go inside; if it does not, the flag wont be updated
// So we can not continue and shoshould destroy the tree if any part created
Flag_OPERATION = 1;

Hr = pIOperation-> get_name (& bstrOperationName );
CHECK_HRESULT (hr, "Can not get Operation names ");

HOPERATION = AddtoTree (hPORT, TVI_SORT, W2A (bstrOperationName), TVIF_TEXT, pIOperation );
: SysFreeString (bstrOperationName );
If (! HOPERATION)
{
Flag = 0;
Goto cleanup;
}
// We do release by assigning to 0
PIOperation = 0;
}
If (flag_OPERATION = 0)
{
Flag = 0;
MSG ("cocould not load OPERATIONS! ");
}
/// We do release by assigning to 0
PIWSDLPort = 0;
}
If (flag_PORT = 0)
{
Flag = 0;
MSG ("cocould not load PORTS! ");
}
/// We do release by assigning to 0
PIWSDLService = 0;
}

If (flag_SERVICE = 0)
{
Flag = 0;
MSG ("cocould not load SERVICE! ");
}
UpdateData (false );

Cleanup:
: SysFreeString (bstrWSDLFileName );
: SysFreeString (bstrServiceName );
: SysFreeString (bstrPortName );
: SysFreeString (bstrOperationName );

If (flag = 0) DestroyTree ();

Return;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.