首页 > 开发 > 综合 > 正文

webservice系列教学(15)-如何调用webservice(vc6)

2024-07-21 02:21:54
字体:
来源:转载
供稿:网友
//////////////////////////////////////////////////////////////////////////////////////////////////
//  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 will return null, otherwise it will return handle of 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 is 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::destroytree()
//
//  parameters: no parameters
//
//  description: deletes the existing tree, if any problem occurs for deleting returns false
//  returns: bool
//
//////////////////////////////////////////////////////////////////////////////////////////////////
bool cmclientdlg::destroytree()
{
    // if any tree 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 be destroyed");
        }

        if (m_parameters.getitemcount() != 0)
        {
            if (m_parameters.deleteallitems() == 0)
            {
                flag = 0;
                msg("parameter list could not 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 item to list");
        }
        // i have to addref() before pisoapmap = 0 , otherwise i will 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;
}
注册会员,创建你的web开发资料库,
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表