WebService series Teaching (15)-How to call WebService (VC6)

Source: Internet
Author: User
Tags bool insert wsdl
Web//////////////////////////////////////////////////////////////////////////////////////////////////
Function:cmclientdlg::addtotree ()
//
Parameters: (Htreeitem hparent, Htreeitem hinsertafter, LPTSTR pszdata, UINT mask, IUnknown
* Theinterface)
//
Description:insert the tree item to tree
//
Returns:htreeitem
//
//////////////////////////////////////////////////////////////////////////////////////////////////
Htreeitem Cmclientdlg::addtotree (Htreeitem hparent, Htreeitem hinsertafter, LPTSTR pszdata, UINT Mask,
IUnknown * theinterface)
{
Tv_insertstruct Curtreeitem;
Htreeitem Hreturn;

Curtreeitem.hparent = hparent;
Curtreeitem.hinsertafter = Hinsertafter;
CurTreeItem.item.pszText = Pszdata;
CurTreeItem.item.mask = Mask | Lvif_param;
CurTreeItem.item.lParam = reinterpret_cast<dword> (theinterface);

Hreturn = M_treectrl.insertitem (&curtreeitem);
If insertion fails, it'll return NULL, otherwise it'll return Handle the new item,
if (Hreturn)
Theinterface->addref ();

return hreturn;
}

//////////////////////////////////////////////////////////////////////////////////////////////////
Function:cmclientdlg::ncountparameter ()
//
Parameters:no parameters
//
Description:counts the number of parameters, the function takes
Returns:int
//
//////////////////////////////////////////////////////////////////////////////////////////////////
int Cmclientdlg::ncountparameter ()
{
Lvitem Item;
int ncounter;
int nnum;
Smisinputenum Isinput;

Nnum = M_parameters.getitemcount ();

for (ncounter = 0; Ncounter <= nnum; Ncounter + +)
{
Assignitem (&item, lvif_param,ncounter,0,0,0);
If could not get the item from list, return-1
if (M_parameters.getitem (&item) = = 0)
return-1;
Reinterpret_cast<isoapmapper *> (Item.lparam)->get_isinput (&isinput);
if (isinput = = smoutput)
Nnum--;
}

return nnum;
}

//////////////////////////////////////////////////////////////////////////////////////////////////
Function:cmclientdlg::modifydialog ()
//
Parameters:no Parameter
//
Description:modifies the Parameter list dialog
Returns:int
//
//////////////////////////////////////////////////////////////////////////////////////////////////
int Cmclientdlg::modifydialog ()
{
Modify the List control dialog, add two more column with their headers
RECT Rlistdialog;
int nreturn = 0;
int flag = 1;

M_parameters.getclientrect (&rlistdialog);

Nreturn = M_parameters.insertcolumn (0, _t ("Variable"), Lvcfmt_left, (Rlistdialog.right-rlistdialog.left)/3);
if (Nreturn = = 1)
{
Flag = 0;
MSG ("Could not modify the dialog");
}
Nreturn =m_parameters.insertcolumn (1, _t ("Type"), Lvcfmt_left, (Rlistdialog.right-rlistdialog.left)/3);
if (Nreturn = = 1)
{
Flag = 0;
MSG ("Could not modify the dialog");
}
Nreturn =m_parameters.insertcolumn (2, _t ("Value"), Lvcfmt_left, (Rlistdialog.right-rlistdialog.left)-(2* ( Rlistdialog.right-rlistdialog.left)/3));
if (Nreturn = = 1)
{
Flag = 0;
MSG ("Could not modify the dialog");
}

UpdateData (FALSE);
Cleanup
if (flag = 0)
return-1;
return 1;
}

//////////////////////////////////////////////////////////////////////////////////////////////////
Function:cmclientdlg::checkforurl ()
//
Parameters:no parameters
//
Description:checks whether URL for WSDL file was given or not. If it is not given, returns-1
Returns:int
//
//////////////////////////////////////////////////////////////////////////////////////////////////
int Cmclientdlg::checkforurl ()
{
int flag = 1;
if (M_strurl.isempty ())
{
Flag = 0;
MSG ("WSDL file is not given");
}
Cleanup
if (flag = 0)
return-1;

return 1;
}

//////////////////////////////////////////////////////////////////////////////////////////////////
Function:cmclientdlg::D estroytree ()
//
Parameters:no parameters
//
Description:deletes the existing tree, if no problem occurs for deleting false
Returns:bool
//
//////////////////////////////////////////////////////////////////////////////////////////////////
BOOL Cmclientdlg::D estroytree ()
{
If any, exist, delete it, and also delete the list
int flag = 1;
if (M_treectrl.getcount ()!= 0)
{
if (!m_treectrl.deleteallitems ())
{
Flag = 0;
MSG ("Tree could not to be destroyed");
}

if (M_parameters.getitemcount ()!= 0)
{
if (m_parameters.deleteallitems () = = 0)
{
Flag = 0;
MSG ("Parameter list could not to be destroyed");;
}
}
}

Cleanup
if (flag ==0)
return false;

return true;
}

//////////////////////////////////////////////////////////////////////////////////////////////////
Function:cmclientdlg::updatelist ()
//
Parameters:no parameters
//
Description:updates parameters of the operation
//
Returns:int
//
//////////////////////////////////////////////////////////////////////////////////////////////////
int Cmclientdlg::updatelist ()
{
Uses_conversion;

Ccomptr<isoapmapper> Pisoapmap;
Ccomptr<ienumsoapmappers> ppienumsoapmappers;
Tvitem Tvitem;

HRESULT hr = S_OK;
Long cfetched;

BSTR bstrelementname = 0;
BSTR bstrelementtype = 0;

Lvitem Lvitem;

CString strtmp;

int ncounter = 0;
int flag = 1;
int flagsm = 0;

Smisinputenum Isinput;

If list is not empty, delete it
if (M_parameters.getitemcount ()!= 0)
{
if (m_parameters.deleteallitems () = = 0)
{
Flag = 0;
MSG ("Could not delete list");
}
}
Get the selected operation
Tvitem.mask = Tvif_param;
Tvitem.hitem = M_treectrl.getselecteditem ();
if (! Tvitem.hitem)
{
Flag = 0;
MSG ("Could not get selected item");
}

if (M_treectrl.getitem (&tvitem) = = 0)
{
Flag = 0;
MSG ("Could not get item");
}

Get parts of the operation

hr = (reinterpret_cast<iwsdloperation *> (Tvitem.lparam))->getoperationparts (&ppienumsoapmappers);
Check_hresult (HR, "Getting operation parts failed");

In this loop take each parameter one by one
while ((hr = Ppienumsoapmappers->next (1, &pisoapmap, &cfetched) = = S_OK) && (Pisoapmap!= NULL))
{
flagsm = 1;
Type of parameter
hr = Pisoapmap->get_elementtype (&bstrelementtype);
Check_hresult (HR, "could not get name of parameter!");

Name of parameter
hr = Pisoapmap->get_elementname (&bstrelementname);
Check_hresult (HR, "Could not get the type of parameter!");

strtmp = Bstrelementtype;

Check what type of parameter it is? [In], [in,out] ...
hr = Pisoapmap->get_isinput (&isinput);
Check_hresult (HR, "Checking input type is failed");

if (isinput = = sminput)
{
Strtmp + = "[In]";
}
else if (isinput = = sminout)
{
Strtmp + = "[In/out]";
}
else if (isinput = = smoutput)
{
Strtmp + = "[out]";
}

Assignitem (&lvitem, Lvif_text | Lvif_param, Ncounter + +, 0,W2A (Bstrelementname),:: Sysstringlen (Bstrelementname));

Lvitem.lparam = (DWORD) (isoapmapper*) Pisoapmap;
Insert the item in to list
if (M_parameters.insertitem (&lvitem) = =-1)
{
Flag = 0;
MSG ("Could not set Item to List");
}

Lvitem.mask = Lvif_text;
Lvitem.isubitem = 1;
Lvitem.psztext = Strtmp.getbuffer (0);
Insert the second column
if (M_parameters.setitem (&lvitem) = = 0)
{
Flag = 0;
MSG ("Could not insert the Item to List");
}
I have to ADDREF () before pisoapmap = 0, otherwise I'll loose the object
((iunknown*) pisoapmap)->addref ();
Release Pisoapmap
Pisoapmap = 0;
}
if (flagsm = 0)
{
Flag = 0;
MSG ("Getting Operation parts failed");
}

UpdateData ();

Cleanup
:: SysFreeString (Bstrelementname);
:: SysFreeString (Bstrelementtype);

if (flag = 0)
return-1;

return 1;
}


Related Article

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.