⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wsdlread.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// 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:    wsdlread.cpp
//
// Contents:
//
//  implementation file
//
//        IWSDLReader Interface implemenation
//
//-----------------------------------------------------------------------------
#ifndef UNDER_CE
#include "msxml2.h"
#include "WinCEUtils.h"
#endif


#include "headers.h"
#include "wsdlread.h"
#include "wsdlserv.h"
#include "wsdloper.h"
#include "enwsdlse.h"
#include "typemapr.h"
#include "xsdpars.h"


BEGIN_INTERFACE_MAP(CWSDLReader)
    ADD_IUNKNOWN(CWSDLReader, IWSDLReader)
    ADD_INTERFACE(CWSDLReader, IWSDLReader)
END_INTERFACE_MAP(CWSDLReader)

/////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CWSDLReader::CWSDLReader()
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
CWSDLReader::CWSDLReader()
{
    m_pWSDLDom = 0;
    m_pWSMLDom = 0;
    m_pServiceList = 0;
#ifndef UNDER_CE
    m_bUseServerHTTPRequest = false;
#endif 
    m_bInitSuccessfull = false;
    m_bLoadOnServer = true;
    m_critSect.Initialize();

    TRACEL((1, "Reader constructed \n\n"));
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CWSDLReader::~CWSDLReader()
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
CWSDLReader::~CWSDLReader()
{
    TRACEL((1, "Reader shutdown \n\n"));
    m_critSect.Delete();

}
/////////////////////////////////////////////////////////////////////////////////////////////////////////





/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CWSDLReader::Load(WCHAR *pchWSDLFileSpec, WCHAR *pchSMLFileSpec)
//
//  parameters:
//
//  description:
//        the load method loads the passed in filespecs into xmldoms to  analyze it's content
//
//  returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CWSDLReader::Load(WCHAR *pchWSDLFileSpec, WCHAR *pchSMLFileSpec)
{
    HRESULT hr = E_FAIL;
    CCritSectWrapper csw(&m_critSect);

    CHK (csw.Enter());

#ifndef CE_NO_EXCEPTIONS
    try
    {
#endif 

        if (m_bInitSuccessfull)
        {
            hr = E_UNEXPECTED;
            globalAddError(WSDL_IDS_INITCALLEDTWICE,WSDL_IDS_READER,  hr);
            goto Cleanup;

        }

        // verify locale existence


        if (IsValidLocale(LCID_TOUSE, LCID_INSTALLED)==0)
        {
            // conversion code will fail, bail out
            hr = E_FAIL;
            globalAddError(WSDL_IDS_ENGLISHNOTINSTALLED, WSDL_IDS_READER, hr);
            goto Cleanup;

        }


        hr = LoadDom(pchWSDLFileSpec, &m_pWSDLDom);
        if (FAILED(hr))
        {
            globalAddError(WSDL_IDS_LOADFAILED,WSDL_IDS_READER,  hr);
            goto Cleanup;
        }

        CHK(CoCreateInstance(CLSID_SoapTypeMapperFactory, NULL,
                              CLSCTX_INPROC_SERVER,
                              IID_ISoapTypeMapperFactory,
                              (void**)&m_ptypeFactory));

        // we need to add the schema to this guy.... pass the whole document for now

        CHK(m_ptypeFactory->addSchema(m_pWSDLDom));


        hr = AnalyzeWSDLDom();

        if (FAILED(hr))
        {
            globalAddError(WSDL_IDS_ANALYZEWSDLFAILED,WSDL_IDS_READER,  hr);
            goto Cleanup;
        }

        if (pchSMLFileSpec && wcslen(pchSMLFileSpec) > 0)
        {
            // only create a failure if a filename was given
            hr = LoadDom(pchSMLFileSpec, &m_pWSMLDom);
            if (FAILED(hr))
            {
                globalAddError(WSML_IDS_WSMLLOADFAILED, WSDL_IDS_READER, hr);
                goto Cleanup;
            }

            hr = AnalyzeWSMLDom();
            if (FAILED(hr))
            {
                globalAddError(WSML_IDS_WSMLANALYZEFAILED, WSDL_IDS_READER, hr);
                goto Cleanup;
            }

        }
#ifndef CE_NO_EXCEPTIONS
    }

    catch(...)
    {
        hr = E_UNEXPECTED;
    }
#endif 


Cleanup:
    if (hr==E_FAIL)
    {
        // change generic failures to E_INVALIDARG, as the failures is 99% sure to be caused
        // by invalid XML passed in
        hr = E_INVALIDARG;
    }
    else if (SUCCEEDED(hr))
    {
        m_bInitSuccessfull = true;
    }
    return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CWSDLReader::GetSoapServices(IEnumWSDLService **ppWSDLServiceEnum)
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CWSDLReader::GetSoapServices(IEnumWSDLService **ppWSDLServiceEnum)
{

    HRESULT hr = S_OK;

    ASSERT(m_pServiceList!=0);

    if (ppWSDLServiceEnum==0)
        return(E_INVALIDARG);

    if (!m_pServiceList)
        return(E_FAIL);

    hr = m_pServiceList->Clone(ppWSDLServiceEnum);


    ASSERT(hr==S_OK);
    return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////






/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CWSDLReader::ParseRequest(IUnknown *pSoapReader, IWSDLPort **ppIWSDLPort, IWSDLOperation **ppIWSDLOperation)
//
//  parameters:
//
//  description:
//        this method is intended as a shortcut to find a certain operation based on
//            an incoming message
//  returns:
//            the operation with all soapmappers filled out
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CWSDLReader::ParseRequest(ISoapReader *pSoapReader, IWSDLPort **ppIWSDLPort,
        IWSDLOperation **ppIWSDLOperation)
{
    HRESULT hr = E_FAIL;
    CAutoRefc<IEnumWSDLService>     pServiceList=0;
    CAutoRefc<IWSDLService>            pService=0;
    CAutoRefc<IEnumWSDLPorts>          pPortList=0;
    CAutoRefc<IWSDLPort>              pPort=0;
    CAutoRefc<IEnumWSDLOperations>     pOperationList=0;
    CAutoRefc<IWSDLOperation>        pOperation=0;
    CAutoBSTR                       bstrSoapAction;
    long                            lFetched=0;

    if (ppIWSDLOperation==0 || pSoapReader==0 || ppIWSDLPort ==0)
    {
        hr = E_INVALIDARG;
        goto Cleanup;
    }

    *ppIWSDLOperation = NULL;
    *ppIWSDLPort = NULL;

    CHK(pSoapReader->get_soapAction(&bstrSoapAction));


    // for now, we use a really bad implmentation:
    //        iterate over all services
    //        iterate over all ports
    //        iterate over all operations
    //            try to load
    //                -> if failed, continue
    //                -> if succeeded, that's the guy, compare the soapaction property

    ASSERT(m_pServiceList!=0);

    if (!m_pServiceList)
    {
        hr = E_FAIL;
        goto Cleanup;
    }

    hr = GetSoapServices(&pServiceList);

    if (FAILED(hr))
    {
        goto Cleanup;
    }


    while(pServiceList->Next(1, &pService, &lFetched)==S_OK)
    {
        hr = pService->GetSoapPorts(&pPortList);
        if (FAILED(hr))
        {
            goto Cleanup;
        }
        while (pPortList->Next(1, &pPort, &lFetched)==S_OK)
        {
            // now we have a port.
            hr = pPort->GetSoapOperations(&pOperationList);
            if (FAILED(hr))
            {
                goto Cleanup;
            }
            while (pOperationList->Next(1, &pOperation, &lFetched)==S_OK)
            {
                // first verify the soapaction
                if (((CWSDLOperation*)(IWSDLOperation*)pOperation)->compareSoapAction(bstrSoapAction))
                {
                    // that matches, try to load the guy
                    hr = pOperation->Load(pSoapReader, VARIANT_TRUE);
                    if (SUCCEEDED(hr))
                    {
                        // found the correct operation
                        *ppIWSDLOperation = pOperation;
                        (*ppIWSDLOperation)->AddRef();
                        *ppIWSDLPort = pPort;
                        pPort->AddRef();
                        goto Cleanup;
                    }
                }
                (pOperation.PvReturn())->Release();
            }
            (pPort.PvReturn())->Release();
            (pOperationList.PvReturn())->Release();
        }
        (pService.PvReturn())->Release();
        (pPortList.PvReturn())->Release();
    }
    // if we did not bail out above, we failed
    if (FAILED(hr))
    {
        // now this means that we tried loading a matching guy and he FAILED while restoring values
        globalAddError(WSDL_IDS_LOADREQUESTFAILED, WSDL_IDS_READER,  hr, bstrSoapAction);
    }
    else
    {
        hr = E_FAIL;
        globalAddError(WSDL_IDS_PARSEREQUESTFAILED, WSDL_IDS_READER,  hr, bstrSoapAction);
    }



Cleanup:
    ASSERT(hr==S_OK);
    return(hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -