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

📄 server.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CSoapServer::ConstructSoapResponse(
                CServerFaultInfo   *pSoapFaultInfo,
                ISoapSerializer *pISoapSerializer,
                IWSDLOperation *pIWSDLOperation,
                IUnknown	   *pStreamOut)
{
    HRESULT     hr = S_OK;
    CAutoRefc<ISOAPError>  pISoapErr;
    CAutoRefc<IErrorInfo>  pIErrInfo;

    CHK(pISoapSerializer->startBody(/* BSTR enc_style_uri */ NULL));
    m_serializerState = enSerializerBody;;

    // Operation was successful
    // we will not arrive here if an error happened before
    CHK(pIWSDLOperation->Save(pISoapSerializer, VARIANT_FALSE));
    hr = S_OK;

Cleanup:
    if (SUCCEEDED(hr))
    {
        // End of Soap body element
        CHK(pISoapSerializer->endBody());
        // Finally end the envelope
        CHK(pISoapSerializer->endEnvelope());
    }
    return hr;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function:  CSoapServer::ConstructGenericSoapErrorMessage(CServerFaultInfo   *pSoapFaultInfo,
//                              ISoapSerializer *pISoapSerializer, DWORD   dwFaultcodeId, DWORD   MsgId,
//                              HRESULT hrRes, WCHAR * pwstrDetail,va_list*Arguments)
//  parameters:
//
//  description:
//        
//  returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CSoapServer::ConstructGenericSoapErrorMessage(
                CServerFaultInfo   *pSoapFaultInfo,
                ISoapSerializer *pISoapSerializer,
                DWORD   dwFaultcodeId,
                DWORD   MsgId,
                HRESULT hrRes,
                WCHAR * pwstrDetail,
                va_list*Arguments)
{
    HRESULT     hr = S_OK;
    CMemWStr                tempbuf;
#ifndef UNDER_CE
    UINT                    buflen;
#endif 

    CHK_BOOL(pSoapFaultInfo && pISoapSerializer, E_FAIL);

#ifndef UNDER_CE
    if (hrRes)
#else
    if(S_OK != hrRes)
#endif 
    {
        if (MsgId == 0)
        {
            // Find a MsgId that most closely relates to the error
            MsgId = HrToMsgId(hrRes);
        }
        CHK(pSoapFaultInfo->FaultMsgFromResHr(dwFaultcodeId,
                MsgId, hrRes, Arguments));
    }
    else
    {
        if (MsgId == 0)
            MsgId = SOAP_IDS_UNSPECIFIED_ERR;
        CHK(pSoapFaultInfo->FaultMsgFromRes(dwFaultcodeId,
                MsgId, NULL, Arguments));
    }

    if (m_serializerState == enSerializerInit)
    {
        CHK(pISoapSerializer->startEnvelope((BSTR)g_pwstrEnvPrefix, (BSTR)g_pwstrEncStyleNS, L""));
        m_serializerState = enSerializerEnvelope;
    }
    if (m_serializerState == enSerializerEnvelope)
    {
        CHK(pISoapSerializer->startBody(/* BSTR enc_style_uri */ NULL));
        m_serializerState = enSerializerBody;
    }
  	CHK(pISoapSerializer->startFault(pSoapFaultInfo->getfaultcode(),
                    pSoapFaultInfo->getfaultstring(),
                    pSoapFaultInfo->getfaultactor(), 
                    pSoapFaultInfo->getNamespace()));

    // Get the detail info here
    if (pSoapFaultInfo->getdetail())
    {
        CHK(pISoapSerializer->startFaultDetail( ));
        if (pSoapFaultInfo->hasISoapError())
        {
            CHK(pISoapSerializer->writeXML(pSoapFaultInfo->getdetail()));
        }
        else
        {
            CHK(pSoapFaultInfo->writeDetailTree(pISoapSerializer));
        }    
        CHK(pISoapSerializer->endFaultDetail());
    }
    CHK(pISoapSerializer->endFault());
    // Reset the fault info, since we have used this one up.
    pSoapFaultInfo->Reset();

    // now reset the global error list
    globalResetErrors();

    


Cleanup:
    if (SUCCEEDED(hr))
    {
        // End of Soap body element
        CHK(pISoapSerializer->endBody());
        // Finally end the envelope
        CHK(pISoapSerializer->endEnvelope());
    }
    ASSERT(hr == S_OK);
    return (hr);
}


/////////////////////////////////////////////////////////////////////////////
// CServerFaultInfo

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CServerFaultInfo::FaultMsgFromRes ( DWORD   dwFaultCodeId, DWORD   dwResourceId, 
//                                                WCHAR * pwstrdetail, va_list *Arguments)
//  parameters:
//
//  description:
//        
//  returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CServerFaultInfo::FaultMsgFromRes
    (
        DWORD   dwFaultCodeId,  // SOAP_IDS_SERVER(default)/SOAP_IDS_MUSTUNDERSTAND/SOAP_IDS_VERSIONMISMATCH
        DWORD   dwResourceId,   // Resource id for the fault string
        WCHAR * pwstrdetail,    // detail part (optional)
       	va_list	*Arguments		// Arguments to be passed to the resource string
    )
{
    CMemBSTR        bstractor;

    if (m_bhasFault)
    {
        // We already have a fault message here
        return S_OK;
    }

    if (dwFaultCodeId == 0)
        dwFaultCodeId = SOAP_IDS_SERVER;
    else
        ASSERT(dwFaultCodeId != SOAP_IDS_CLIENT);

    // Fill in the CFaultInfo members
	if (m_pIWSDLPort && FAILED(m_pIWSDLPort->get_address(&bstractor)))
	{
	    return E_FAIL;
	}
	return  CFaultInfo::FaultMsgFromResourceString(
                dwFaultCodeId,
                dwResourceId,
                (WCHAR *) pwstrdetail,
                (WCHAR *) bstractor.get(),
       	        Arguments);

}


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CServerFaultInfo::FaultMsgFromResHr (DWORD dwFaultCodeId, DWORD dwResourceId,
//                                                 HRESULT hrErr, va_list *Arguments)
//  parameters:
//
//  description:
//        
//  returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CServerFaultInfo::FaultMsgFromResHr
    (
        DWORD   dwFaultCodeId,
        DWORD   dwResourceId,
        HRESULT hrErr,
       	va_list	*Arguments
    )
{
    CMemBSTR        bstractor;

    if (m_bhasFault)
    {
        // We already have a fault message here
        return S_OK;
    }

    if (hrErr == WSDL_MUSTUNDERSTAND)
        dwFaultCodeId = SOAP_IDS_MUSTUNDERSTAND;

    if (dwFaultCodeId == 0)
    {
        dwFaultCodeId = SOAP_IDS_SERVER;
    }
    else
        ASSERT(dwFaultCodeId != SOAP_IDS_CLIENT);

    // Fill in the CFaultInfo members
	if (m_pIWSDLPort && FAILED(m_pIWSDLPort->get_address(&bstractor)))
	{
	    return E_FAIL;
	}

    return  CFaultInfo::FaultMsgFromResourceHr (
                dwFaultCodeId,
                dwResourceId,
                hrErr,
                (WCHAR *)bstractor.get(),
                Arguments);

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function:     HRESULT CServerFaultInfo::writeDetailTree(ISoapSerializer *pSerializer)
//
//  parameters:
//
//  description:
//      this will persist the detail information in a namespace declared subtree inside
//      the fault detail
//  returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CServerFaultInfo::writeDetailTree(ISoapSerializer *pSerializer)
{
    HRESULT hr = S_OK;
    CErrorListEntry *pErrorList;

    TCHAR               achBuffer[ONEK+1];



    CHK(pSerializer->startElement((BSTR)g_pwstrErrorInfoElement, 0, 0, (BSTR)g_pwstrErrorNSPrefix));
    CHK(pSerializer->SoapNamespace((BSTR)g_pwstrErrorNSPrefix, (BSTR)g_pwstrMSErrorNS));

    CHK(pSerializer->startElement((BSTR)g_pwstrErrorReturnHR,  0, 0, (BSTR)g_pwstrErrorNSPrefix));
    getReturnCodeAsString(achBuffer, 0);
    CHK(pSerializer->writeString(achBuffer));
    CHK(pSerializer->endElement());

    // before we start the callstack, we write out the errorinfo info, assuming there is some
    globalGetError(&pErrorList);

    if (pErrorList && pErrorList->Size() > 0)
    {
        CHK(saveErrorInfo(pSerializer, pErrorList));
        CHK(pSerializer->startElement((BSTR) g_pwstrErrorCallstack, 0, 0, (BSTR)g_pwstrErrorNSPrefix));
        CHK(saveFaultDetail(pSerializer, pErrorList));
    }
    else
    {
        // if we don't have a global error list, just persist the detail string information
        CHK(pSerializer->startElement((BSTR) g_pwstrErrorCallstack, 0, 0, (BSTR)g_pwstrErrorNSPrefix));
        CHK(pSerializer->startElement((BSTR) g_pwstrErrorCallElement, 0, 0, (BSTR)g_pwstrErrorNSPrefix));
        CHK(pSerializer->startElement((BSTR) g_pwstrErrorDescription, 0, 0, (BSTR)g_pwstrErrorNSPrefix));
        CHK(pSerializer->writeString(getdetail()));
        CHK(pSerializer->endElement());
        CHK(pSerializer->endElement());
    }
    // close the callstack
    CHK(pSerializer->endElement());
    // close the errorinfo
    CHK(pSerializer->endElement());

Cleanup:

    ASSERT(SUCCEEDED(hr));
    return(hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CServerFaultInfo::saveFaultDetail(ISoapSerializer *pSerializer, CErrorListEntry *pErrorList)
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CServerFaultInfo::saveFaultDetail(ISoapSerializer *pSerializer, CErrorListEntry *pErrorList)
{
    HRESULT hr = S_OK;
    UINT                uiSize;
    CErrorDescription   *pError;
    TCHAR               achBuffer[ONEK+1];

    uiSize = pErrorList->Size();

    for (int i=0; i < (int)uiSize;i++ )
    {
        pError = pErrorList->GetAt(i);
        if (wcslen(pError->GetDescription())>0)
        {
            CHK(pSerializer->startElement((BSTR) g_pwstrErrorCallElement, 0, 0, (BSTR)g_pwstrErrorNSPrefix));
            CHK(pSerializer->startElement((BSTR) g_pwstrErrorComponent, 0, 0, (BSTR)g_pwstrErrorNSPrefix));
            CHK(pSerializer->writeString(pError->GetComponent()));
            CHK(pSerializer->endElement());

            CHK(pSerializer->startElement((BSTR)g_pwstrErrorDescription, 0, 0, (BSTR)g_pwstrErrorNSPrefix));
            CHK(pSerializer->writeString(pError->GetDescription()));
            CHK(pSerializer->endElement());

            CHK(pSerializer->startElement((BSTR) g_pwstrErrorReturnHR, 0, 0, (BSTR)g_pwstrErrorNSPrefix));
            getReturnCodeAsString(achBuffer, pError);
            CHK(pSerializer->writeString(achBuffer));
            CHK(pSerializer->endElement());
            CHK(pSerializer->endElement());
        }
    }


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

}


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CServerFaultInfo::saveErrorInfo(ISoapSerializer *pSerializer, CErrorListEntry *pErrorList)
//
//  parameters:
//
//  description:
//      if the errorlist holds on to an ErrorInfo structure, save it
//  returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CServerFaultInfo::saveErrorInfo(ISoapSerializer *pSerializer, CErrorListEntry *pErrorList)
{
    HRESULT hr;
    CAutoBSTR bstrDescription;
    CAutoBSTR bstrHelpFile;
    CAutoBSTR bstrSource;
    DWORD    dwHelpContext;
    HRESULT   hrFromSource;
    TCHAR     achBuffer[ONEK];

    // returns S_FALSE if no valid errorinfo was stored
    hr = pErrorList->GetErrorInfo(&bstrDescription, &bstrSource, &bstrHelpFile, &dwHelpContext, &hrFromSource);

    if (hr==S_OK)
    {
        CHK(pSerializer->startElement((BSTR) g_pwstrErrorServerElement, 0, 0, (BSTR)g_pwstrErrorNSPrefix));

        if(bstrDescription)
        {
            CHK(pSerializer->startElement((BSTR) g_pwstrErrorDescription, 0, 0, (BSTR)g_pwstrErrorNSPrefix));
            CHK(pSerializer->writeString(bstrDescription));
            CHK(pSerializer->endElement());
        }
        if (bstrSource)
        {
            CHK(pSerializer->startElement((BSTR) g_pwstrErrorSource, 0, 0, (BSTR)g_pwstrErrorNSPrefix));
            CHK(pSerializer->writeString(bstrSource));
            CHK(pSerializer->endElement());
        }

        if (bstrHelpFile)
        {
            CHK(pSerializer->startElement((BSTR) g_pwstrErrorHelpFile, 0, 0, (BSTR)g_pwstrErrorNSPrefix));
            CHK(pSerializer->writeString(bstrHelpFile));
            CHK(pSerializer->endElement());

            CHK(pSerializer->startElement((BSTR) g_pwstrErrorHelpContext, 0, 0, (BSTR)g_pwstrErrorNSPrefix));
            swprintf(achBuffer, _T("%ld"), dwHelpContext);
            CHK(pSerializer->writeString(achBuffer));
            CHK(pSerializer->endElement());
        }
        CHK(pSerializer->endElement());
    }
    hr = S_OK;



Cleanup:
    return hr;
}



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: TCHAR * CServerFaultInfo::getReturnCodeAsString(TCHAR *pchBuffer, CErrorDescription *pError)
//
//  parameters:
//
//  description:
//      if no error description is passed in,
//          checks if there is one and returns top of stack
//          or returns hrError
//  returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void CServerFaultInfo::getReturnCodeAsString(TCHAR *pchBuffer, CErrorDescription *pError)
{
    HRESULT hrError;

    hrError = m_hrError;

    if (!pError)
    {
        CErrorListEntry     *pErrorList;

        globalGetError(&pErrorList);
        if (pErrorList)
        {
            pErrorList->GetReturnCode(&hrError);
        }
    }
    else
    {
        hrError = pError->GetErrorCode();
    }

    swprintf(pchBuffer, L"%ld", hrError);

}


⌨️ 快捷键说明

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