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

📄 soapmapr.cpp

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




/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CSoapMapper::Save(ISoapSerializer *pISoapSerializer, BSTR bstrEncoding, enEncodingStyle enStyle,
//									 BSTR bstrMessageNS, long lFlags)
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapMapper::Save(ISoapSerializer *pISoapSerializer, BSTR bstrEncoding, enEncodingStyle enStyle, BSTR bstrMessageNS, long lFlags)
{
	HRESULT	 hr;
	HRESULT hrFromTypeMapper; 
	VARIANT *pVar;
	BOOL    fSaveHREF;
	TCHAR   achhref[_MAX_ATTRIBUTE_LEN];
	BOOL    fCreatedInnerElement = true; 

	ASSERT(m_pTypeMapper);

    CHK_BOOL(m_pTypeMapper, E_UNEXPECTED);
	CHK_BOOL (pISoapSerializer, E_INVALIDARG);

    fSaveHREF = lFlags & c_saveIDRefs; 


    if (!fSaveHREF)
    {
        // we only need the value if we are actually going to call the typemapper here
        pVar = m_variantList.Lookup(GetCurrentThreadId()); 
        CHK_BOOL(pVar, E_INVALIDARG);
    }    
    CHK_BOOL(enStyle!=enDocumentEncoded, E_INVALIDARG);

    switch (enStyle)
    {
        case enRPCLiteral:
            if (!m_basedOnType)
            {
                // need to add the partname as a wrapper element for part element=
                // put it into the method namespace by using the prefix
            	CHK (pISoapSerializer->startElement(getPartName(), bstrMessageNS, NULL, NULL) ); 
               	CHK (pISoapSerializer->startElement(getVarName(), m_bstrSchemaURI, NULL, NULL));
            }
            else
            {
                // if based on type, no wrapper, but the partname is the wrapper anyway and is the the message namespace
               	CHK (pISoapSerializer->startElement(getVarName(), bstrMessageNS, NULL, NULL));
            }
            break;
        case enDocumentLiteral:
            if (!m_basedOnType)
            {
                // if based on type, we do NOT write a wrapper element
               	CHK (pISoapSerializer->startElement(getVarName(), m_bstrSchemaURI, NULL, NULL));
            }   	
            else
            {
                fCreatedInnerElement = false;
            }
           	break;
        case enRPCEncoded:
            CHK (pISoapSerializer->startElement(getVarName(), NULL, NULL, NULL) );    
            break;
    }

    if (fSaveHREF)
    {
        // now add the href attribute to the element
        swprintf(achhref, _T("#%d"), m_lparameterOrder+2);

        CHK(pISoapSerializer->SoapAttribute( 
    							(BSTR)g_pwstrHref,			// name,
    							L"",				// ns_uri,
    							achhref,	// value
    							L""));					// prefix

        hrFromTypeMapper = S_OK;							
    }			
    else
    {
    	hrFromTypeMapper = m_pTypeMapper->write (pISoapSerializer, bstrEncoding, enStyle, 0, pVar); 
    }	

	
	// now end the inner element
	if (fCreatedInnerElement)
	{
	    // will be false for document/literal/type
    	CHK (pISoapSerializer->endElement());
	}	

 
	if (enStyle == enRPCLiteral  && m_basedOnType==false)
    {
        // need to close the partname as a wrapper element
        CHK (pISoapSerializer->endElement());
    }    

	hr = hrFromTypeMapper; 

Cleanup:
	ASSERT(hr==S_OK);
    
	if (FAILED(hr))
	{
	     globalAddError(WSML_IDS_TYPEMAPPERSAVE, WSDL_IDS_MAPPER, hr, m_bstrSchemaElement);                                               
	}
    
	return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CSoapMapper::SaveValue(ISoapSerializer *pISoapSerializer, BSTR bstrEncoding, enEncodingStyle enStyle)
//
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapMapper::SaveValue(ISoapSerializer *pISoapSerializer, BSTR bstrEncoding, enEncodingStyle enStyle)
{
    HRESULT hr; 
    HRESULT hrFromTypeMapper;
    
	TCHAR   achhref[_MAX_ATTRIBUTE_LEN];
	VARIANT *pVar;

	ASSERT(m_pTypeMapper);

    CHK_BOOL(m_pTypeMapper, E_UNEXPECTED);
	CHK_BOOL (pISoapSerializer, E_INVALIDARG);

    pVar = m_variantList.Lookup(GetCurrentThreadId()); 

    CHK_BOOL(pVar, E_INVALIDARG);
    CHK_BOOL(enStyle!=enDocumentEncoded, E_INVALIDARG);

	
	// now write the value element
    CHK (pISoapSerializer->startElement(_T("soapValue"), NULL, NULL, NULL) );        

    swprintf(achhref, _T("%d"), m_lparameterOrder+2);
	CHK(pISoapSerializer->SoapAttribute( 
							_T("id"),			// name,
							L"",				// ns_uri,
							achhref,	// value
							L""));					// prefix

	// store the hr from the typemapper away, we need to close the elements no matter what happens
	hrFromTypeMapper = m_pTypeMapper->write (pISoapSerializer, bstrEncoding, enStyle, 0, pVar); 

	// now end the inner element
	CHK (pISoapSerializer->endElement());


	hr = hrFromTypeMapper; 
Cleanup:
    return (hr);
    
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function:HRESULT CSoapMapper::Load(IXMLDOMNode *pNodeRoot, BSTR bstrEncoding, enEncodingStyle enStyle, 
//									BSTR bstrMessageNS)
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapMapper::Load(IXMLDOMNode *pNodeRoot, BSTR bstrEncoding, enEncodingStyle enStyle, BSTR bstrMessageNS)
{
	HRESULT 	hr = E_FAIL;
	CAutoRefc<IXMLDOMNode> pNode; 
	CAutoRefc<IXMLDOMNode> pSearch; 	
	CVariant varIn;
 	XPathState  xp;
	CAutoFormat     autoFormat;
	

    CHK_BOOL(enStyle!=enDocumentEncoded, E_INVALIDARG);
    CHK (xp.init(pNodeRoot));

	VariantInit(&varIn);

	ASSERT(m_pTypeMapper);
    CHK_BOOL(m_pTypeMapper, E_UNEXPECTED);


    CHK(autoFormat.sprintf(_T("xmlns:%s='%s'"), g_pwstrMessageSchemaNSPrefix, m_bstrSchemaURI));
    CHK (xp.setLanguage(g_pwstrXpathLanguage)); //give us enc: for encoding    
    CHK (xp.addNamespace(&autoFormat)); //give us m:messageNamespace    
    
    if (bstrMessageNS)
    {
        CHK(autoFormat.sprintf(_T("xmlns:%s='%s'"), g_pwstrMessageNSPrefix, bstrMessageNS));
        CHK (xp.addNamespace(&autoFormat)); //give us m:messageNamespace
    }


	// let's first go and select the correct subnode for our element
	// the way to FIND the node is different pending modes:
	//  in document mode we always look for the correctly named element
	//  in rpc encoded mode we mostly look for the correctly named element
	//      only when we are the RESULT, we take the FIRST childnode

	if (enStyle > enDocumentEncoded && m_lparameterOrder == -1)
	{
	    // so if we are IN RPC mode AND we are the RESULT, we ignore all name rules.
        // find the first child of the body here
        showNode(pNodeRoot);
        CHK(_WSDLUtilFindFirstChild(pNodeRoot, &pSearch));
        showNode(pSearch);
        if (enStyle == enRPCLiteral && m_basedOnType == false)
        {
            CHK(_WSDLUtilFindFirstChild(pSearch, &pNode));            
            showNode(pNode);
        }
        else
        {
            pNode = pSearch.PvReturn();
        }
	}
    else
    {
        switch (enStyle)
        {
            case enRPCLiteral:
                {
                    CAutoFormat     afPart;

                    // construct first part of the search string based on the message namespace
           	        if (bstrMessageNS)
           	        {
           	            CHK(afPart.sprintf(_T("%s:%s"), g_pwstrMessageNSPrefix, getPartName()));
           	        }
           	        else
           	        {
           	             CHK(afPart.copy(getPartName()));
           	        }
                    
                    if (!m_basedOnType)
                    {
                        CHK(autoFormat.sprintf(_T("%s/%s:%s"), &afPart, g_pwstrMessageSchemaNSPrefix , getVarName()));
                    }
                    else
                    {
                        // we have no wrapper, so we look for message:part
                        CHK(autoFormat.copy(&afPart));
                    }
                }
                break;

                
            case enDocumentLiteral:
                if (!m_basedOnType)
                {
                    CHK(autoFormat.sprintf(_T("%s:%s"), g_pwstrMessageSchemaNSPrefix , getVarName()));
                }    
                else
                {
                    // now we do NOT make a lookup, we just  assign the node
                    pNode = pNodeRoot;
                    pNode->AddRef();
                }
                break;
                
            case enRPCEncoded:
                // if encoded, no namespace added
                CHK(autoFormat.copy(getVarName()));
                break;
        }
        if (!pNode)
        {
            // should not be true for document/literal/@type
            CHK(pNodeRoot->selectSingleNode(&autoFormat, &pNode));
        }    
    }

        
    CHK_BOOL(pNode, E_INVALIDARG);

    // now we do have the correct SOAPMAPPER node. This might be a node with an href attribute. check for it
    CHK (FollowHref(&pNode) );
    

    CHK(m_pTypeMapper->read(pNode, bstrEncoding, enStyle, 0, (VARIANT *)&varIn) );

    // if we are the mapper did not claim to return an array or variant

    if (   !(m_vtType & VT_SAFEARRAY) &&  !(m_vtType & VT_ARRAY) &&  !(m_vtType & VT_VARIANT) )
    {
        // check if typemapr returned correct vartype compared to what he told us before
        CHK_BOOL((V_VT((VARIANT*)&varIn) == m_vtType), E_INVALIDARG);
    }
    
    CHK (put_comValue((VARIANT)varIn));

Cleanup:
	VariantClear(&varIn);    
    if (FAILED(hr))
    {
         globalAddError(WSML_IDS_TYPEMAPPERPUTSOAPVALUE, WSDL_IDS_MAPPER, hr, m_bstrSchemaElement);                                               
    }

	return (hr);

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






/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CSoapMapper::PrepareVarOut(VARIANT *pVarOut)
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapMapper::PrepareVarOut(VARIANT *pVarOut)
{
	HRESULT hr = S_OK;
	if (!pVarOut)
	{
		hr = E_INVALIDARG;
		goto Cleanup;
	}

    memset(pVarOut, 0, sizeof(VARIANT));
	V_VT(pVarOut) = (VARTYPE)m_vtType;;

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

⌨️ 快捷键说明

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