📄 wsdlserv.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft shared
// source or premium shared source license agreement under which you licensed
// this source code. If you did not accept the terms of the license agreement,
// you are not authorized to use this source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the SOURCE.RTF on your install media or the root of your tools installation.
// THE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//+----------------------------------------------------------------------------
//
//
// File: wsdlserv.cpp
//
// Contents:
//
// implementation file
//
// IWSDLReader Interface implemenation
//
// Created
//
//-----------------------------------------------------------------------------
#include "headers.h"
#include "wsdlserv.h"
#include "wsdlport.h"
#include "ensoappt.h"
#ifdef UNDER_CE
#include "WinCEUtils.h"
#endif
BEGIN_INTERFACE_MAP(CWSDLService)
ADD_IUNKNOWN(CWSDLService, IWSDLService)
ADD_INTERFACE(CWSDLService, IWSDLService)
END_INTERFACE_MAP(CWSDLService)
BEGIN_INTERFACE_MAP(CDispatchHolder)
ADD_IUNKNOWN(CDispatchHolder, IUnknown)
END_INTERFACE_MAP(CDispatchHolder)
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: CWSDLService::CWSDLService()
//
// parameters:
//
// description:
//
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
CWSDLService::CWSDLService()
{
m_pPortsList = 0;
m_cbDispatchHolders=0;
m_pDispatchHolders=0;
m_bCustomMappersCreated = false;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: CWSDLService::~CWSDLService()
//
// parameters:
//
// description:
//
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
CWSDLService::~CWSDLService()
{
TRACEL((2, "Service shutdown %S\n", m_bstrName));
for (int i=0; m_pDispatchHolders && i < m_cbDispatchHolders;i++ )
{
if (m_pDispatchHolders[i])
m_pDispatchHolders[i]->Release();
}
delete [] m_pDispatchHolders;
release(&m_pPortsList);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CWSDLService::get_name(BSTR *bstrServiceName)
//
// parameters:
//
// description:
//
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CWSDLService::get_name(BSTR *bstrServiceName)
{
return _WSDLUtilReturnAutomationBSTR(bstrServiceName, m_bstrName);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CWSDLService::get_documentation(BSTR *pbstrServicedocumentation)
//
// parameters:
//
// description:
//
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CWSDLService::get_documentation(BSTR *pbstrServicedocumentation)
{
return _WSDLUtilReturnAutomationBSTR(pbstrServicedocumentation, m_bstrDocumentation);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CWSDLService::GetSoapPorts(IEnumWSDLPorts **ppIWSDLPorts)
//
// parameters:
//
// description:
//
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CWSDLService::GetSoapPorts(IEnumWSDLPorts **ppIWSDLPorts)
{
HRESULT hr = S_OK;;
ASSERT(m_pPortsList!=0);
if (ppIWSDLPorts==0)
return(E_INVALIDARG);
hr = m_pPortsList->Clone(ppIWSDLPorts);
ASSERT(hr==S_OK);
return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CWSDLService::Init(IXMLDOMNode *pServiceNode, ISoapTypeMapperFactory *ptypeFactory)
//
// parameters:
//
// description:
// walks the service node, get's the information it needs and creates holding
// objects for the subparts
//
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CWSDLService::Init(IXMLDOMNode *pServiceNode, ISoapTypeMapperFactory *ptypeFactory)
{
HRESULT hr = E_FAIL;
IXMLDOMNode *pPort = 0;
CAutoRefc<IXMLDOMNodeList> pNodeList=0;
CWSDLPort *pPortDesc=0;
long lFetched;
// first we need to get the attributes collection and find the "name" of this
hr = _WSDLUtilFindAttribute(pServiceNode, _T("name"), &m_bstrName);
if (FAILED(hr))
{
globalAddError(WSDL_IDS_SERVICENONAME, WSDL_IDS_SERVICE, hr);
goto Cleanup;
}
// hold on to the typefactory for later
assign(&m_pTypeFactory, ptypeFactory);
TRACEL((2, "Service Init %S\n", m_bstrName));
// find the documentation subnode and get text if exists
CHK(_WSDLUtilFindDocumentation(pServiceNode, &m_bstrDocumentation));
// now find the ports subnode and get the portobject
hr = pServiceNode->selectNodes(_T("def:port"), &pNodeList);
if (FAILED(hr))
{
globalAddError(WSDL_IDS_SERVICENOPORTDEF, WSDL_IDS_SERVICE, hr, m_bstrName);
goto Cleanup;
}
m_pPortsList = new CSoapObject<CEnumWSDLPorts>(INITIAL_REFERENCE);
if (!m_pPortsList)
{
hr = E_OUTOFMEMORY;
goto Cleanup;
}
// iterate over all services and get the guys...
while (((hr = pNodeList->nextNode(&pPort))==S_OK) && pPort != 0)
{
pPortDesc = new CSoapObject<CWSDLPort>(1);
if (!pPortDesc)
{
hr = E_OUTOFMEMORY;
goto Cleanup;
}
hr = pPortDesc->Init(pPort, ptypeFactory);
if (FAILED(hr))
{
globalAddError(WSDL_IDS_SERVICEPORTINITFAILED, WSDL_IDS_SERVICE,hr, m_bstrName);
release(&pPortDesc);
goto Cleanup;
}
if (hr == S_OK)
{
// on S_FALSE, not a SOAP_PORT, ignore the guy
hr = m_pPortsList->Add(pPortDesc);
if (FAILED(hr))
{
goto Cleanup;
}
}
release(&pPort);
release(&pPortDesc);
}
// if we got here and there is anything in the list, everything is fine
hr = m_pPortsList->Size(&lFetched);
if (SUCCEEDED(hr) && lFetched > 0)
{
hr = S_OK;
}
else
{
globalAddError(WSDL_IDS_SERVICENOPORTSDEFINED, WSDL_IDS_SERVICE,hr, m_bstrName);
hr = E_INVALIDARG;
}
Cleanup:
release(&pPortDesc);
release(&pPort);
ASSERT(hr==S_OK);
release(&pPort);
return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CWSDLService::AddWSMLMetaInfo(IXMLDOMNode *pServiceNode, IXMLDOMDocument *pWSDLDom,
// IXMLDOMDocument *pWSMLDom, bool bLoadOnServer)
//
// parameters:
//
// description:
// does not have to do anything so far, beside:
// a) check if this is a match
// b) call subsequent objects
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CWSDLService::AddWSMLMetaInfo(IXMLDOMNode *pServiceNode,
IXMLDOMDocument *pWSDLDom,
IXMLDOMDocument *pWSMLDom,
bool bLoadOnServer)
{
HRESULT hr = E_FAIL;
CAutoRefc<IXMLDOMNode> pUsing=0;
CAutoRefc<IXMLDOMNodeList> pNodeList=0;
CAutoBSTR bstrTemp;
long cb;
#ifndef UNDER_CE
BOOL bCachable;
#endif
CWSDLPort *pPortDesc=0;
long lFetched;
hr = _WSDLUtilFindAttribute(pServiceNode, _T("name"), &bstrTemp);
if (FAILED(hr))
{
globalAddError(WSML_IDS_SERVICENONAME, WSDL_IDS_SERVICE, hr);
goto Cleanup;
}
if (wcscmp(bstrTemp, m_bstrName)==0)
{
// see if there is an headerHandler attribute, ignore failure, as there does not need to be one
_WSDLUtilFindAttribute(pServiceNode, g_pwstrHeaderHandlerAttribute, &m_bstrHeaderHandler);
hr = pServiceNode->selectNodes(_T("./using"), &pNodeList);
if (FAILED(hr))
{
globalAddError(WSML_IDS_SERVICENOUSING, WSDL_IDS_SERVICE, hr, m_bstrName);
goto Cleanup;
}
// create the list to hold the objects
hr = pNodeList->get_length(&m_cbDispatchHolders);
if (FAILED(hr))
{
goto Cleanup;
}
if (m_cbDispatchHolders > 0)
{
// allocated the pointers
m_pDispatchHolders = (CDispatchHolder**)new BYTE[sizeof(CDispatchHolder*) * m_cbDispatchHolders];
if (!m_pDispatchHolders)
{
hr = E_OUTOFMEMORY;
goto Cleanup;
}
ZeroMemory(m_pDispatchHolders, sizeof(CDispatchHolder*) * m_cbDispatchHolders);
cb = 0;
while (((hr = pNodeList->nextNode(&pUsing))==S_OK) && pUsing!=0)
{
bstrTemp.Clear();
m_pDispatchHolders[cb] = new CSoapObject<CDispatchHolder>(INITIAL_REFERENCE);
#ifdef UNDER_CE
CHK_BOOL(m_pDispatchHolders[cb], E_OUTOFMEMORY);
#endif
// parse the using pointer and get the values stored.
// we need the PROGID
hr = _WSDLUtilFindAttribute(pUsing, _T("cachable"), &bstrTemp);
if (SUCCEEDED(hr))
{
m_pDispatchHolders[cb]->m_bCachable = (BOOL) _wtoi(bstrTemp);
}
hr = _WSDLUtilFindAttribute(pUsing, _T("PROGID"), &(m_pDispatchHolders[cb]->m_bstrProgID));
if (FAILED(hr))
{
globalAddError(WSML_IDS_SERVICENOPROGID, WSDL_IDS_SERVICE, hr, m_bstrName);
goto Cleanup;
}
hr = _WSDLUtilFindAttribute(pUsing, _T("ID"), &(m_pDispatchHolders[cb]->m_bstrID));
if (FAILED(hr))
{
globalAddError(WSML_IDS_SERVICENOID, WSDL_IDS_SERVICE, hr, m_bstrName);
goto Cleanup;
}
CHK(m_pDispatchHolders[cb]->Init());
release(&pUsing);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -