webservice系列教學(15)-如何調用webservice(vc6)

來源:互聯網
上載者:User
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;
}


相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。