web//////////////////////////////////////////////////////////////////////////////////////////////////
// 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;
}
webservice系列教学(14)-如何调用webservice(vc5)
80酷酷网 80kuku.com