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

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 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;
}

时间: 2024-10-28 05:03:28

webservice系列教学(15)-如何调用webservice(vc6)的相关文章

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

web 4.如何调用webservice4.0 webservice的调用过程    客户端:取得服务端的服务描述文件WSDL,解析该文件的内容,了解服务端的服务信息,以及调用方式.根据需要,生成恰当的SOAP请求消息(指定调用的方法,已经调用的参数),发往服务端.等待服务端返回的SOAP回应消息,解析得到返回值. 服务端:生成服务描述文件,以供客户端获取.接收客户端发来的SOAP请求消息,解析其中的方法调用和参数格式.根据WSDL和WSML的描述,调用相应的COM对象来完成指定功能,并把返回值

webservice系列教学(6)-如何调用webservice(C#,)

web 4. 5使用C#调用无需下载任何组件新建项目Visual C#项目windows应用程序.在解决方案资源管理器中添加web引用,输入wsdl文件所在地址.将web引用改名.yundan.(service_name)即可引用*需引用System.web.services*例程:using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windo

webservice系列教学(5)-如何调用webservice(Jscript,vbscript)

js|jscript|vbscript|web 4. 3 在asp中使用Jscript调用需下载msSoapToolkit20.exe引用:MSSOAP.SoapClient    例程:    <%@ LANGUAGE = JScript %><HTML><HEAD><TITLE>webservice演示</TITLE></HEAD><BODY>    <%         var WSDL_URL = "

webservice系列教学(8)-如何调用webservice(vb.net)

web 4.7使用vb.net调用无需下载任何组件新建项目Visual Basic项目windows应用程序.在解决方案资源管理器中添加web引用,输入wsdl文件所在地址.将web引用改名为yundan.yundan.(service_name)即可引用*需引用System.web.services*例程:    Public Class Form1        Inherits System.Windows.Forms.Form#Region " Windows 窗体设计器生成的代码

webservice系列教学(9)-如何调用webservice(vb6.0,vbscript)

vbscript|web 4.8使用vb6.0调用需下载msSoapToolkit20.exe添加引用:Microsoft Soap Type Library 位置:"C:\Program Files\Common Files\MSSoap\Binaries\ MSSOAP1.dll"    调用方法:    Dim cc As New MSSOAPLib.SoapClient    例程:    新建工程标准EXE添加3个textbox控件,text1,text2,text3添

webservice系列教学(4)-如何调用webservice(pb,java)

web 4.1 使用PowerBuilder调用    适用版本8.0 需下载Bulletin Web Services Toolkit 4.14.2使用java调用需要下载apache soap.下载地址:http://xml.apache.org/soap/index.html导入:import org.apache.soap.*;import org.apache.soap.rpc.*;例程:import java.io.*;import java.util.*;import java.n

webservice系列教学(10)-如何调用webservice(vc1)

web 4.10使用vc调用需下载msSoapToolkit20.exe    引用#import "msxml3.dll" using namespace MSXML2;#import "C:\Program Files\Common Files\MSSoap\Binaries\mssoap1.dll" exclude("IStream", "ISequentialStream", "_LARGE_INTEGER&

webservice系列教学(7)-如何调用webservice(javascript)

需下载msSoapToolkit20.exe引用:MSSOAP.SoapClient    例程:var WSDL_URL = "http://192.168.0.4/yundan/service1.wsdl"WScript.echo("Connecting: " + WSDL_URL)var Calc = WScript.CreateObject("MSSOAP.SoapClient")Calc.mssoapinit(WSDL_URL, &qu

webservice系列教学(16)-如何调用webservice(vc7)

web ////////////////////////////////////////////////////////////////////////////////////////////////////  function: CMClientDlg::assignItem()////  parameters: (LVITEM *item, UINT mask, int iItem, int iSubItem, LPTSTR pszText, int cchTextMax) ////  de