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

📄 wsdloper.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    return(E_NOTIMPL);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////





/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CWSDLOperation::Save(ISoapSerializer *pISoapSerializer, VARIANT_BOOL vbInput)
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CWSDLOperation::Save(ISoapSerializer *pISoapSerializer, VARIANT_BOOL vbInput)
{

    HRESULT                     hr=S_OK;
    ISoapMapper                    *pSoapMapper=0;

#ifndef UNDER_CE
    long                        lFetched;
#endif 
    CWSDLMessagePart            *pMessageToUse;
    CAutoRefc<IEnumSoapMappers> pEnumMappers;
    bool                        fUseNameSpace=false;
    bool                        fUseWrapper;
    DWORD                       dwCookie;
    enEncodingStyle             enStyle;
    long                       lFlags=0;


    pMessageToUse = vbInput==VARIANT_TRUE ? m_pWSDLInputMessage : m_pWSDLOutputMessage;

    fUseWrapper = m_fDocumentMode==false || pMessageToUse->needsWrapper();

    if (m_fDocumentMode)
    {
        enStyle = enDocumentLiteral;
    }
    else
    {
        enStyle = pMessageToUse->IsLiteral() ? enRPCLiteral : enRPCEncoded;
    }

    if (fUseWrapper)
    {
        // we only write the wrapper for RPC mode

        fUseNameSpace = (pMessageToUse->IsLiteral() && pMessageToUse->GetNameSpace()==0);

        if (pMessageToUse->needsWrapper())
        {
            hr = pISoapSerializer->startElement(pMessageToUse->GetWrapperName(), 0, 0, 0);
            pISoapSerializer->SoapDefaultNamespace(pMessageToUse->GetNameSpace());
        }
        else
        {
            hr = pISoapSerializer->startElement(pMessageToUse->GetWrapperName(),
                        fUseNameSpace ? 0 : pMessageToUse->GetNameSpace(),
                        NULL,
                        NULL);
        }

        if (FAILED(hr))
        {
            ASSERT("Writing first message part to stream failed");
            hr = E_FAIL;
            goto Cleanup;
        }
    }
    // once you can handle different namespaces, you can replace L"m" with NULL and a
    // new namespace will  be generated

    if (m_fCreateHrefs)
    {
        lFlags |= c_saveIDRefs;
    }
    dwCookie = 0;
    // now walk over the mappers for the input/output method and serialize them
    while (pMessageToUse->getMappers()->getNext(&pSoapMapper, &dwCookie)==S_OK)
    {
        // set the encoding for this operation
        CHK(pSoapMapper->Save(pISoapSerializer, pMessageToUse->GetEncodingStyle(), enStyle, !fUseNameSpace ? pMessageToUse->GetNameSpace() : 0, lFlags));
        release(&pSoapMapper);
    }

    if (m_fCreateHrefs)
    {
        if (fUseWrapper)
        {
            // close the RPC mode element
            CHK(pISoapSerializer->endElement());
            fUseWrapper = false;
        }

        dwCookie = 0;
        // now walk over the mappers for the input/output method and serialize them
        while (pMessageToUse->getMappers()->getNext(&pSoapMapper, &dwCookie)==S_OK)
        {
            // set the encoding for this operation
            CHK(((CSoapMapper*)(ISoapMapper*)pSoapMapper)->SaveValue(pISoapSerializer, pMessageToUse->GetEncodingStyle(), (enEncodingStyle)enStyle));
            release(&pSoapMapper);
        }
    }


Cleanup:
    release(&pSoapMapper);

    if (fUseWrapper)
    {
        // close the RPC mode element
        if (FAILED(pISoapSerializer->endElement()))
        {
            ASSERT("Writing method end stream failed");
            hr = E_FAIL;
        }
    }
    // now we are done...

    if (FAILED(hr))
    {
        globalSetActor(m_bstrSoapAction);
    }
    ASSERT(hr == S_OK);
    return(hr);

}





/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CWSDLOperation::Load(ISoapReader *pISoapReader, VARIANT_BOOL vbInput)
//
//  parameters:
//
//  description:
//      this works as follows:
//          RPC mode -> search for the wrapper element with a namespace qualified XPath
//          docuement mdoe -> search for the SOAP:BODY
//          pass this as a parent element into the soapmapper load routines
//  returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CWSDLOperation::Load(ISoapReader *pISoapReader, VARIANT_BOOL vbInput)
{
    HRESULT                        hr = E_FAIL;
    CAutoRefc<IXMLDOMNode>         pRootNode=0;
    CAutoRefc<IXMLDOMNode>         pNode=0;
    CAutoRefc<IEnumSoapMappers> pEnumMappers;
    ISoapMapper                    *pSoapMapper=0;
#ifndef UNDER_CE
    long                        lFetched;
#endif 
    CWSDLMessagePart            *pMessageToUse;
    bool                        fUseWrapper;
    DWORD                       dwCookie;
    enEncodingStyle                enStyle;
    bool                        bUseMessageNS=false;
    CAutoFormat                 autoFormat;



    hr = _WSDLUtilGetRootNodeFromReader(pISoapReader, &pRootNode);
    if (FAILED(hr))
    {
        goto Cleanup;
    }


    pMessageToUse = vbInput==VARIANT_TRUE ? m_pWSDLInputMessage : m_pWSDLOutputMessage;
    fUseWrapper = m_fDocumentMode==false || pMessageToUse->needsWrapper();

    if (m_fDocumentMode)
    {
        enStyle = enDocumentLiteral;
    }
    else
    {
        enStyle = pMessageToUse->IsLiteral() ? enRPCLiteral : enRPCEncoded;
    }

    // set up search queries and the bUseMessageNS flag
    if (fUseWrapper)
    {
        // search the RPC wrapper element
        // prepare namespace lookup
        if (pMessageToUse->IsLiteral() && pMessageToUse->GetNameSpace()==0)
        {
            // if literal, there will be no explicit namespace, preparesetup for global soap envelope namespace
            // so look for SOAPENV:BODY/message
            hr = _XPATHUtilPrepareLanguage(pRootNode, (WCHAR*)g_pwstrMessageNSPrefix, (WCHAR*)g_pwstrEnvNS);
            CHK(autoFormat.sprintf(_T("//%s:%s/%s"), g_pwstrMessageNSPrefix, _T("Body"), pMessageToUse->GetWrapperName()));

        }
        else
        {
            // if encode, there will be an explicit namespace, preparesetup for local  namespace
            // and look for namespace:message
            hr = _XPATHUtilPrepareLanguage(pRootNode, (WCHAR*)g_pwstrMessageNSPrefix, pMessageToUse->GetNameSpace());
            CHK(autoFormat.sprintf(_T("//%s:%s"), g_pwstrMessageNSPrefix, pMessageToUse->GetWrapperName()));
            bUseMessageNS= enStyle == enRPCLiteral;

        }
        CHK(hr);
    }


    // this indicates loading a request. Here all kind of complicated rules apply, if we have a wrapper or not
    if (vbInput == VARIANT_TRUE)
    {
        if (fUseWrapper)
        {
            // now let's see if we are there.
            hr = _XPATHUtilFindNodeFromRoot(pRootNode, &autoFormat, &pNode);
            if (hr != S_OK)
            {
                hr = E_INVALIDARG;
                goto Cleanup;
            }
            // now we should have the correct node
            // walk over the mappers and tell them to load themselves....

            if (bUseMessageNS==false)
            {
                // reset the namespace lookup
                // if the namespace of the message IS used, we will do xpath lookup in the mappers as well...
                _XPATHUtilResetLanguage(pRootNode);
            }

        }
        else
        {
            CHK(findBodyNode(pRootNode, &pNode));
        }
    }
    else
    {
        // now if we load a response everything is easy. just go and find the body and take it's first child node
        CAutoRefc<IXMLDOMNode> pBody;

        CHK(findBodyNode(pRootNode, &pBody));

        if (fUseWrapper)
        {
            CHK(_WSDLUtilFindFirstChild(pBody, &pNode));
        }
        else
        {
            pNode = pBody.PvReturn();
        }
    }

    // now walk over the mappers for the input/output method and load them

    dwCookie = 0;

    showNode(pNode);

    // now walk over the mappers for the input/output method and serialize them
    while (pMessageToUse->getMappers()->getNext(&pSoapMapper, &dwCookie)==S_OK)
    {
        hr = pSoapMapper->Load(pNode, pMessageToUse->GetEncodingStyle(), enStyle, bUseMessageNS ? pMessageToUse->GetNameSpace() : 0);
        if (FAILED(hr))
        {
            //    value and the fragment was not found for this mapper.
            goto Cleanup;
        }
        release(&pSoapMapper);
    }


Cleanup:
    if (FAILED(hr) && hr != E_INVALIDARG)
    {
        globalSetActor(m_bstrSoapAction);
    }

    release(&pSoapMapper);
    return(hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CWSDLOperation::findBodyNode(IXMLDOMNode *pRootNode, IXMLDOMNode **ppNode)
//
//  parameters:
//      node as return value
//  description:
//      finds the soap/body node
//  returns:
//      S_OK found it
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CWSDLOperation::findBodyNode(IXMLDOMNode *pRootNode, IXMLDOMNode **ppNode)
{
    HRESULT hr;
    CAutoFormat autoFormat;

    // find the SOAP:BODY element
    // prepare namespace lookup
    CHK( _XPATHUtilPrepareLanguage(pRootNode, (WCHAR*)g_pwstrMessageNSPrefix, (WCHAR*)g_pwstrEnvNS));
    // now let's see if we are there.
    // first find body/header
    CHK(autoFormat.sprintf(_T("//%s:%s"), g_pwstrMessageNSPrefix, _T("Body")));
    hr = _XPATHUtilFindNodeFromRoot(pRootNode, &autoFormat, ppNode);
    if (hr != S_OK)
    {
        hr = E_INVALIDARG;
        goto Cleanup;
    }
    // now we should have the correct node
    // walk over the mappers and tell them to load themselves....
    _XPATHUtilResetLanguage(pRootNode);

Cleanup:
    return hr;

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




/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CWSDLOperation::verifyPartName(smIsInputEnum snInput, TCHAR *pchPartName)
//
//  parameters:
//
//  description:
//       verifies that the partname is unique in the current mapper collection
//  returns:
//      S_OK: yep, unique
//      E_FAIL: nope, not unique
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CWSDLOperation::verifyPartName(smIsInputEnum snInput, TCHAR *pchPartName)
{
    HRESULT                        hr = E_FAIL;
    ISoapMapper                    *pSoapMapper=0;
#ifndef UNDER_CE
    LONG                        lFetched;
#endif 
    DWORD                     dwCookie;
    smIsInputEnum               inOut;

    dwCookie = 0;
    while(m_pEnumSoapMappers->getNext(&pSoapMapper, &dwCookie)==S_OK)
    {
        pSoapMapper->get_isInput(&inOut);
        if (inOut == snInput)
        {
            if (wcscmp(((CSoapMapper*)pSoapMapper)->getPartName(), pchPartName)==0)
            {
                hr = E_FAIL;
                goto Cleanup;
            }
        }


        release(&pSoapMapper);
    }
    hr = S_OK;


Cleanup:
    release(&pSoapMapper);
    return(hr);

}




/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CWSDLOperation::get_hasHeader( VARIANT_BOOL *pbHeader)
//
//  parameters:
//
//  description:
//
//  returns:
//
//////////////////////////

⌨️ 快捷键说明

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