webservice系列教学(14)-如何调用webservice(vc5)-.NET教程,Web Service开发

webservice系列教学(14)-如何调用webservice(vc5)-.NET教程,Web Service开发
//
//  function: cmclientdlg::ondeleteitemlistparam()
//
//  parameters: (nmhdr* pnmhdr, lresult* presult)
//
//  description: for each row of list, it calls the 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 calls the 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 should go inside; if it does not, the flag wont be updated
        // so we can not continue and should 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 should go inside; if it does not, the flag wont be updated
            // so we can not continue and should 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 should go inside; if it does not, the flag wont be updated
             // so we can not continue and should 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("could not load  operations!");
            }
             we do release by assigning to 0
            piwsdlport = 0;
        }
        if (flag_port == 0)
        {
            flag =0;
            msg("could not load  ports!");
        }
         we do release by assigning to 0
        piwsdlservice = 0;
    }
    
    if (flag_service == 0)
    {
        flag =0;
        msg("could not load  service!");
    }
    updatedata(false);

cleanup:
    ::sysfreestring(bstrwsdlfilename);
       ::sysfreestring(bstrservicename);
    ::sysfreestring(bstrportname);
    ::sysfreestring(bstroperationname);


    if (flag == 0)
        destroytree();

    return;
}


文章整理:西部数码--专业提供 域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值