当前位置:编程学习 > C#/ASP.NET >>

怎么调用webservice

敢问各位大侠一个问题,我有一个webservice的地址,例如:http://192.168.0.138/Tweb/Tsoap
没有暴露WSDL,没有暴露调用哪个asmx文件,请问我该如何调用里面的protest()方法?小弟是初学者,请各位指教了 --------------------编程问答-------------------- webservice系列教学(14)-如何调用webservice(vc5)-.NET教程,Web Service开发 
 
作者:网友供稿 点击:7  
 
  西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!虚拟主机可在线rar解压,自动数据恢复设置虚拟目录等.虚拟主机免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金! 
 
 
文章页数:[1]   
 
//////////////////////////////////////////////////////////////////////////////////////////////////
//  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;

 
 
--------------------编程问答-------------------- 看不懂这位大哥写的 --------------------编程问答-------------------- 在vs里面添加服务引用
写入你的服务网址
就会得到服务的客户类
   理论上wsdl就是http://192.168.0.138/Tweb/Tsoap?wsdl --------------------编程问答-------------------- 加个?wsdl --------------------编程问答-------------------- 我也看不懂啊  --------------------编程问答-------------------- 在项目里面 鼠标右键   添加web引用     简单吧 。。。
补充:.NET技术 ,  Web Services
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,