// CwmsoapmsgObj.cpp : Implementation of CCwmsoapmsgObj

#include "stdafx.h"
#include "wmsoapmsgObj.h"

// CCwmsoapmsgObj

STDMETHODIMP CwmsoapmsgObj::Initialize(BSTR bstrSvcName, BSTR bstrPortName, BSTR bstrNodeURI, BSTR bstrSOAPAction, BSTR bstrNextHopURL, VARIANT_BOOL bExplicitTypingEnabled, VARIANT_BOOL bNodeTypeEnabled, IDispatch *pIDispatch, VARIANT_BOOL *pResult)
{
	bool bRtn = m_pSOAPMsg->Initialize( wstring(bstrSvcName),
										wstring(bstrPortName),
										wstring(bstrNodeURI),
										wstring(bstrSOAPAction),
										wstring(bstrNextHopURL),
										bExplicitTypingEnabled == VARIANT_TRUE ? true : false,
                                        bNodeTypeEnabled == VARIANT_TRUE ? true : false,
										pIDispatch);
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::Deserialize(VARIANT_BOOL *pResult)
{
	*pResult = (m_pSOAPMsg->Deserialize() == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::Serialize(VARIANT_BOOL *pResult)
{
	*pResult = (m_pSOAPMsg->Serialize() == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::IsSOAPFault(VARIANT_BOOL *pResult)
{
	*pResult = (m_pSOAPMsg->IsSOAPFault() == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetNumHeaderElems(long *plNumber)
{
	*plNumber = m_pSOAPMsg->GetNumHeaderElems();
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::AddHeaderElem(BSTR bstrNamespaceURI, BSTR bstrName, VARIANT varContent, VARIANT_BOOL bMustUnderstand, BSTR bstrActorURI, VARIANT_BOOL *pResult)
{
	bool bRtn = m_pSOAPMsg->AddHeaderElem(wstring(bstrNamespaceURI),
										 wstring(bstrName),
										 _variant_t(varContent),
										 bMustUnderstand == VARIANT_TRUE ? true : false,
										 wstring(bstrActorURI),
                                         false, // SOAP 1.2 "relay" attribute == false
                                         false); // inserted at this node, not rcvd in msg
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetFirstHeaderElem(BSTR *pbstrNamespaceURI, BSTR *pbstrName, VARIANT *pvarContent, VARIANT_BOOL *pbMustUnderstand, BSTR *pbstrActorURI, long *plPosition, VARIANT_BOOL *pResult)
{
    long lPos;
    WMSOAPHeaderMsgElement *pHdrElem;
	bool bRtn = m_pSOAPMsg->GetFirstHeaderElem( &pHdrElem,
												lPos);
	if (bRtn == true)
	{
        *pbstrNamespaceURI = SysAllocString(pHdrElem->m_wstrNamespaceURI.c_str());
        *pbstrName = SysAllocString(pHdrElem->m_wstrName.c_str());
        *pbMustUnderstand = (pHdrElem->m_bMustUnderstand == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrActorURI = SysAllocString(pHdrElem->m_wstrActor.c_str());
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
    return VariantCopy(pvarContent, &pHdrElem->m_varContent);
}

STDMETHODIMP CwmsoapmsgObj::GetNextHeaderElem(BSTR *pbstrNamespaceURI, BSTR *pbstrName, VARIANT *pvarContent, VARIANT_BOOL *pbMustUnderstand, BSTR *pbstrActorURI, long *plPosition, VARIANT_BOOL *pResult)
{
	long lPos = *plPosition;
    WMSOAPHeaderMsgElement *pHdrElem;
	bool bRtn = m_pSOAPMsg->GetNextHeaderElem(  &pHdrElem,
												lPos);

	if (bRtn == true)
	{
        *pbstrNamespaceURI = SysAllocString(pHdrElem->m_wstrNamespaceURI.c_str());
        *pbstrName = SysAllocString(pHdrElem->m_wstrName.c_str());
        *pbMustUnderstand = (pHdrElem->m_bMustUnderstand == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrActorURI = SysAllocString(pHdrElem->m_wstrActor.c_str());
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return VariantCopy(pvarContent, &pHdrElem->m_varContent);
}

STDMETHODIMP CwmsoapmsgObj::GetHeaderElem(BSTR bstrNamespaceURI, BSTR bstrName, VARIANT *pvarContent, VARIANT_BOOL *pResult)
{
	_variant_t varContent;
	bool bRtn = m_pSOAPMsg->GetHeaderElem(  wstring(bstrNamespaceURI),
											wstring(bstrName),
											varContent);
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return VariantCopy(pvarContent, &varContent);
}

STDMETHODIMP CwmsoapmsgObj::GetNumMethodParams(long *plNumber)
{
	*plNumber = m_pSOAPMsg->GetNumMethodParams();
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::AddMethodParam(BSTR bstrNamespaceURI, BSTR bstrName, VARIANT varContent, VARIANT_BOOL bIsInParam, VARIANT_BOOL bIsOutParam, VARIANT_BOOL *pResult)
{
	bool bRtn = m_pSOAPMsg->AddMethodParam(  wstring(bstrNamespaceURI),
											 wstring(bstrName),
											 _variant_t(varContent),
											 bIsInParam == VARIANT_TRUE ? true : false,
											 bIsOutParam == VARIANT_TRUE ? true : false);
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetFirstMethodParam(BSTR *pbstrNamespaceURI, BSTR *pbstrName, VARIANT *pvarContent, VARIANT_BOOL *pbIsInParam, VARIANT_BOOL *pbIsOutParam, long *plPosition, VARIANT_BOOL *pResult)
{
	wstring wstrNSURI, wstrName;
	_variant_t varContent;
	bool bIsInParam, bIsOutParam;
	long lPos;
	bool bRtn = m_pSOAPMsg->GetFirstMethodParam(wstrNSURI,
												wstrName,
												varContent,
												bIsInParam,
												bIsOutParam,
												lPos);
	if (bRtn == true)
	{
		*pbstrNamespaceURI = SysAllocString(wstrNSURI.c_str());
		*pbstrName = SysAllocString(wstrName.c_str());
		*pbIsInParam = (bIsInParam == true ? VARIANT_TRUE : VARIANT_FALSE);
		*pbIsOutParam = (bIsOutParam == true ? VARIANT_TRUE : VARIANT_FALSE);
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return VariantCopy(pvarContent, &varContent);
}

STDMETHODIMP CwmsoapmsgObj::GetNextMethodParam(BSTR *pbstrNamespaceURI, BSTR *pbstrName, VARIANT *pvarContent, VARIANT_BOOL *pbIsInParam, VARIANT_BOOL *pbIsOutParam, long *plPosition, VARIANT_BOOL *pResult)
{
	wstring wstrNSURI, wstrName;
	_variant_t varContent;
	bool bIsInParam, bIsOutParam;
	long lPos = *plPosition;
	bool bRtn = m_pSOAPMsg->GetNextMethodParam( wstrNSURI,
												wstrName,
												varContent,
												bIsInParam,
												bIsOutParam,
												lPos);
	if (bRtn == true)
	{
		*pbstrNamespaceURI = SysAllocString(wstrNSURI.c_str());
		*pbstrName = SysAllocString(wstrName.c_str());
		*pbIsInParam = (bIsInParam == true ? VARIANT_TRUE : VARIANT_FALSE);
		*pbIsOutParam = (bIsOutParam == true ? VARIANT_TRUE : VARIANT_FALSE);
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return VariantCopy(pvarContent, &varContent);
}

STDMETHODIMP CwmsoapmsgObj::ClearMethodParams()
{
	m_pSOAPMsg->ClearMethodParams();
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::ClearHeaderElems()
{
	m_pSOAPMsg->ClearHeaderElems();
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetMethodNS(BSTR *pbstrNS)
{
	wstring wstrNS = m_pSOAPMsg->GetMethodNS();
	*pbstrNS = SysAllocString(wstrNS.c_str());
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::SetMethodNS(BSTR bstrNS)
{
	m_pSOAPMsg->SetMethodNS(wstring(bstrNS));
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetMethodName(BSTR *pbstrName)
{
	*pbstrName = SysAllocString(m_pSOAPMsg->GetMethodName().c_str());
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::SetMethodName(BSTR bstrName)
{
	m_pSOAPMsg->SetMethodName(wstring(bstrName));
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetReturnValue(VARIANT *pvarValue)
{
	_variant_t varTemp = m_pSOAPMsg->GetReturnValue();
	return VariantCopy(pvarValue, &varTemp);
}

STDMETHODIMP CwmsoapmsgObj::SetReturnValue(VARIANT varValue)
{
	m_pSOAPMsg->SetReturnValue(varValue);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetSOAPAction(BSTR *pbstrSOAPAction)
{
	*pbstrSOAPAction = SysAllocString(m_pSOAPMsg->GetSOAPAction().c_str());
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::SetSOAPAction(BSTR bstrSOAPAction)
{
	m_pSOAPMsg->SetSOAPAction(wstring(bstrSOAPAction));
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetNodeURI(BSTR *pbstrNodeURI)
{
	*pbstrNodeURI = SysAllocString(m_pSOAPMsg->GetNodeURI().c_str());
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::SetNodeURI(BSTR bstrNodeURI)
{
	m_pSOAPMsg->SetNodeURI(wstring(bstrNodeURI));
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetBuffer(VARIANT *pvarBuffer, VARIANT_BOOL *pResult)
{
	// make SAFEARRAY
	bool bRtn = true;
	void *pData;
	SAFEARRAY *pArray = SafeArrayCreateVector(VT_UI1, 0, m_pSOAPMsg->GetBufferLength());
	if (pArray == NULL || FAILED(SafeArrayAccessData(pArray, &pData)))
	{
		if (pArray != NULL)
		{
			SafeArrayDestroy(pArray);
		}
		bRtn = false;
	}
	else
	{
		memcpy(pData, m_pSOAPMsg->GetBufferPtr(), m_pSOAPMsg->GetBufferLength());
		SafeArrayUnaccessData(pArray);
		pvarBuffer->vt |= (VT_ARRAY | VT_UI1);
		pvarBuffer->parray = pArray;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::SetBuffer(VARIANT varBuffer, VARIANT_BOOL *pResult)
{
	// check SAFEARRAY
	*pResult = VARIANT_FALSE;
	SAFEARRAY *pArray = varBuffer.parray;
	if (((varBuffer.vt & VT_TYPEMASK) & (VT_ARRAY | VT_UI1)) == false ||
			pArray == NULL ||
			SafeArrayGetDim(pArray) != 1)
	{
		return S_OK;
	}
	void *pData;
	if (FAILED(SafeArrayAccessData(pArray, &pData)))
	{
		return S_OK;
	}
	char *pszBuffer = (char *)malloc(pArray->rgsabound[0].cElements);
	if (pszBuffer == NULL)
	{
		return S_OK;
	}
	memcpy(pszBuffer, pData, pArray->rgsabound[0].cElements);
	m_pSOAPMsg->SetBuffer(pszBuffer, pArray->rgsabound[0].cElements);
	SafeArrayUnaccessData(pArray);
	*pResult = VARIANT_TRUE;
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::SetSOAPFault(BSTR bstrFaultCode, BSTR bstrFaultCodeNS, BSTR bstrFaultString, VARIANT_BOOL bNeedDetail, VARIANT_BOOL *pResult)
{

	bool bRtn = m_pSOAPMsg->SetSOAPFault(   wstring(bstrFaultCode),
                                            wstring(bstrFaultCodeNS),
											wstring(bstrFaultString),
											wstring(L""),
											bNeedDetail == VARIANT_TRUE ? true : false);
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::SetSOAP12Fault(BSTR bstrCode, BSTR bstrCodeNS, BSTR bstrSubcode, BSTR bstrSubcodeNS, BSTR bstrReason, BSTR bstrReasonLangId, VARIANT_BOOL *pResult)
{
    map<wstring, wstring> mapReasonText;
    mapReasonText[wstring(bstrReasonLangId)] = wstring(bstrReason);
	bool bRtn = m_pSOAPMsg->SetSOAPFault(   wstring(bstrCode),
                                            wstring(bstrCodeNS),
                                            wstring(bstrSubcode),
                                            wstring(bstrSubcodeNS),
										    mapReasonText,
										    wstring(L""),
                                            false);
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::AddSOAP12ReasonText(BSTR bstrText, BSTR bstrLangId)
{
	m_pSOAPMsg->AddReasonText(  wstring(bstrText), wstring(bstrLangId));
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetFirstSOAP12ReasonText(BSTR *pbstrText, BSTR *pbstrLangId, long *plPosition, VARIANT_BOOL *pResult)
{
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetNextSOAP12ReasonText(BSTR *pbstrText, BSTR *pbstrLangId, long *plPosition, VARIANT_BOOL *pResult)
{
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetSOAP12ReasonText(BSTR bstrLangId, BSTR *pbstrText, VARIANT_BOOL *pResult)
{
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetNumFaultHeaderElems(long *plNumber)
{
	*plNumber = m_pSOAPMsg->GetNumFaultHeaderElems();
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::AddFaultHeaderElem(BSTR bstrNamespaceURI, BSTR bstrName, VARIANT varContent, VARIANT_BOOL bMustUnderstand, BSTR bstrActorURI, VARIANT_BOOL *pResult)
{
	bool bRtn = m_pSOAPMsg->AddFaultHeaderElem(  wstring(bstrNamespaceURI),
												 wstring(bstrName),
												 _variant_t(varContent),
												 bMustUnderstand == VARIANT_TRUE ? true : false,
												 wstring(bstrActorURI),
                                                 false);
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetFirstFaultHeaderElem(BSTR *pbstrNamespaceURI, BSTR *pbstrName, VARIANT *pvarContent, VARIANT_BOOL *pbMustUnderstand, BSTR *pbstrActorURI, long *plPosition, VARIANT_BOOL *pResult)
{
	long lPos;
    WMSOAPHeaderMsgElement *pHdrElem;
	bool bRtn = m_pSOAPMsg->GetFirstFaultHeaderElem(&pHdrElem,
													lPos);
	if (bRtn == true)
	{
        *pbstrNamespaceURI = SysAllocString(pHdrElem->m_wstrNamespaceURI.c_str());
        *pbstrName = SysAllocString(pHdrElem->m_wstrName.c_str());
        *pbMustUnderstand = (pHdrElem->m_bMustUnderstand == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrActorURI = SysAllocString(pHdrElem->m_wstrActor.c_str());
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return VariantCopy(pvarContent, &pHdrElem->m_varContent);
}

STDMETHODIMP CwmsoapmsgObj::GetNextFaultHeaderElem(BSTR *pbstrNamespaceURI, BSTR *pbstrName, VARIANT *pvarContent, VARIANT_BOOL *pbMustUnderstand, BSTR *pbstrActorURI, long *plPosition, VARIANT_BOOL *pResult)
{
	long lPos = *plPosition;
    WMSOAPHeaderMsgElement *pHdrElem;
	bool bRtn = m_pSOAPMsg->GetNextFaultHeaderElem( &pHdrElem,
													lPos);
	if (bRtn == true)
	{
        *pbstrNamespaceURI = SysAllocString(pHdrElem->m_wstrNamespaceURI.c_str());
        *pbstrName = SysAllocString(pHdrElem->m_wstrName.c_str());
        *pbMustUnderstand = (pHdrElem->m_bMustUnderstand == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrActorURI = SysAllocString(pHdrElem->m_wstrActor.c_str());
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return VariantCopy(pvarContent, &pHdrElem->m_varContent);
}

STDMETHODIMP CwmsoapmsgObj::ClearFaultHeaderElems()
{
	m_pSOAPMsg->ClearFaultHeaderElems();
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetNumFaultDetailElems(long *plNumber)
{
	*plNumber = m_pSOAPMsg->GetNumFaultDetailElems();
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::AddFaultDetailElem(BSTR bstrNamespaceURI, BSTR bstrName, VARIANT varContent, VARIANT_BOOL *pResult)
{
	bool bRtn = m_pSOAPMsg->AddFaultDetailElem(  wstring(bstrNamespaceURI),
												 wstring(bstrName),
												 _variant_t(varContent));
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetFirstFaultDetailElem(BSTR *pbstrNamespaceURI, BSTR *pbstrName, VARIANT *pvarContent, long *plPosition, VARIANT_BOOL *pResult)
{
	wstring wstrNSURI, wstrName, wstrActor;
	_variant_t varContent;
	long lPos;
	bool bRtn = m_pSOAPMsg->GetFirstFaultDetailElem(wstrNSURI,
													wstrName,
													varContent,
													lPos);
	if (bRtn == true)
	{
		*pbstrNamespaceURI = SysAllocString(wstrNSURI.c_str());
		*pbstrName = SysAllocString(wstrName.c_str());
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return VariantCopy(pvarContent, &varContent);
}

STDMETHODIMP CwmsoapmsgObj::GetNextFaultDetailElem(BSTR *pbstrNamespaceURI, BSTR *pbstrName, VARIANT *pvarContent, long *plPosition, VARIANT_BOOL *pResult)
{
	wstring wstrNSURI, wstrName, wstrActor;
	_variant_t varContent;
	long lPos = *plPosition;
	bool bRtn = m_pSOAPMsg->GetNextFaultDetailElem( wstrNSURI,
													wstrName,
													varContent,
													lPos);
	if (bRtn == true)
	{
		*pbstrNamespaceURI = SysAllocString(wstrNSURI.c_str());
		*pbstrName = SysAllocString(wstrName.c_str());
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return VariantCopy(pvarContent, &varContent);
}

STDMETHODIMP CwmsoapmsgObj::ClearFaultDetailElems()
{
	m_pSOAPMsg->ClearFaultDetailElems();
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::CheckMustUnderstand(VARIANT_BOOL *pResult)
{
	*pResult = (m_pSOAPMsg->CheckMustUnderstand() == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::SetRequestPhase(VARIANT_BOOL bFlag)
{
	m_pSOAPMsg->SetRequestPhase(bFlag == VARIANT_TRUE ? true : false);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::IsRequestPhase(VARIANT_BOOL *pResult)
{
	*pResult = (m_pSOAPMsg->IsRequestPhase() == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::ClearSOAPFault()
{
	m_pSOAPMsg->ClearSOAPFault();
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetNextHopURL(BSTR *bstrNextHopURL)
{
	*bstrNextHopURL = SysAllocString(m_pSOAPMsg->GetNextHopURL().c_str());
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::SetNextHopURL(BSTR bstrNextHopURL)
{
	m_pSOAPMsg->SetNextHopURL(wstring(bstrNextHopURL));
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::IsIntermediary(VARIANT_BOOL *pResult)
{
	*pResult = (m_pSOAPMsg->IsIntermediary() == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetFaultDetailElem(BSTR bstrNamespaceURI, BSTR bstrName, VARIANT *pvarContent, VARIANT_BOOL *pResult)
{
	_variant_t varContent;
	bool bRtn = m_pSOAPMsg->GetFaultDetailElem( wstring(bstrNamespaceURI),
												wstring(bstrName),
												varContent);
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return VariantCopy(pvarContent, &varContent);
}

STDMETHODIMP CwmsoapmsgObj::GetSOAPFaultCode(BSTR *bstrFaultCode)
{
	*bstrFaultCode = SysAllocString(m_pSOAPMsg->GetSOAPFaultCode().c_str());
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetSOAPFaultCodeNS(BSTR *bstrFaultCodeNS)
{
	*bstrFaultCodeNS = SysAllocString(m_pSOAPMsg->GetSOAPFaultCodeNS().c_str());
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetSOAPFaultString(BSTR *bstrFaultString)
{
	*bstrFaultString = SysAllocString(m_pSOAPMsg->GetSOAPFaultString().c_str());
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetSOAPFaultNode(BSTR *bstrFaultNode)
{
	*bstrFaultNode = SysAllocString(m_pSOAPMsg->GetSOAPFaultNode().c_str());
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetServiceName(BSTR *pbstrServiceName)
{
	*pbstrServiceName = SysAllocString(m_pSOAPMsg->GetServiceName().c_str());
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetPortName(BSTR *pbstrPortName)
{
	*pbstrPortName = SysAllocString(m_pSOAPMsg->GetPortName().c_str());
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::ProcessRPC(VARIANT_BOOL *pResult)
{
	*pResult = (m_pSOAPMsg->ProcessRPC() == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::ProcessRPCGet(BSTR bstrSvcURI, BSTR bstrExtraPath, BSTR bstrQueryString, VARIANT_BOOL *pResult)
{
	*pResult = (m_pSOAPMsg->ProcessRPCGet(wstring(bstrSvcURI), wstring(bstrExtraPath), wstring(bstrQueryString)) == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::IsRPCStyle(VARIANT_BOOL *pResult)
{
	*pResult = (m_pSOAPMsg->IsRPCStyle() == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::AddFaultHeaderElemLiteral(BSTR bstrNamespaceURI, BSTR bstrName, BSTR bstrLiteralXML, VARIANT_BOOL bMustUnderstand, BSTR bstrActorURI, BSTR bstrEncodingStyle, VARIANT_BOOL *pResult)
{
	bool bRtn = m_pSOAPMsg->AddFaultHeaderElemLit(   wstring(bstrNamespaceURI),
													 wstring(bstrName),
													 wstring(bstrLiteralXML),
													 bMustUnderstand == VARIANT_TRUE ? true : false,
													 wstring(bstrActorURI),
                                                     false,
													 wstring(bstrEncodingStyle));
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}
	
STDMETHODIMP CwmsoapmsgObj::GetNumFaultHeaderElemsLiteral(long *plNumber)
{
	*plNumber = m_pSOAPMsg->GetNumFaultHeaderElemsLit();
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetFirstFaultHeaderElemLiteral(BSTR *pbstrNamespaceURI, BSTR *pbstrName, BSTR *pbstrLiteralXML, VARIANT_BOOL *pbMustUnderstand, BSTR *pbstrActorURI, BSTR *pbstrEncodingStyle, long *plPosition, VARIANT_BOOL *pResult)
{
	long lPos;
    WMSOAPHeaderMsgElementLit *pHdrElemLit;
	bool bRtn = m_pSOAPMsg->GetFirstFaultHeaderElemLit( &pHdrElemLit,
														lPos);
	if (bRtn == true)
	{
        *pbstrLiteralXML = SysAllocString(pHdrElemLit->m_wstrLiteralXML.c_str());
        *pbstrNamespaceURI = SysAllocString(pHdrElemLit->m_wstrNamespaceURI.c_str());
        *pbstrName = SysAllocString(pHdrElemLit->m_wstrName.c_str());
        *pbMustUnderstand = (pHdrElemLit->m_bMustUnderstand == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrActorURI = SysAllocString(pHdrElemLit->m_wstrActor.c_str());
        *pbstrEncodingStyle = SysAllocString(pHdrElemLit->m_wstrEncodingStyle.c_str());
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetNextFaultHeaderElemLiteral(BSTR *pbstrNamespaceURI, BSTR *pbstrName, BSTR *pbstrLiteralXML,  VARIANT_BOOL *pbMustUnderstand,  BSTR *pbstrActorURI, BSTR *pbstrEncodingStyle, long *plPosition, VARIANT_BOOL *pResult)
{
	long lPos = *plPosition;
    WMSOAPHeaderMsgElementLit *pHdrElemLit;
	bool bRtn = m_pSOAPMsg->GetNextFaultHeaderElemLit(  &pHdrElemLit,
														lPos);
	if (bRtn == true)
	{
        *pbstrLiteralXML = SysAllocString(pHdrElemLit->m_wstrLiteralXML.c_str());
        *pbstrNamespaceURI = SysAllocString(pHdrElemLit->m_wstrNamespaceURI.c_str());
        *pbstrName = SysAllocString(pHdrElemLit->m_wstrName.c_str());
        *pbMustUnderstand = (pHdrElemLit->m_bMustUnderstand == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrActorURI = SysAllocString(pHdrElemLit->m_wstrActor.c_str());
        *pbstrEncodingStyle = SysAllocString(pHdrElemLit->m_wstrEncodingStyle.c_str());
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::AddHeaderElemLiteral(BSTR bstrNamespaceURI, BSTR bstrName, BSTR bstrLiteralXML, VARIANT_BOOL bMustUnderstand, BSTR bstrActorURI, BSTR bstrEncodingStyle, VARIANT_BOOL *pResult)
{
	bool bRtn = m_pSOAPMsg->AddHeaderElemLit(wstring(bstrNamespaceURI),
											 wstring(bstrName),
											 wstring(bstrLiteralXML),
											 bMustUnderstand == VARIANT_TRUE ? true : false,
											 wstring(bstrActorURI),
                                             false, // SOAP 1.2 "relay" attribute == false
											 wstring(bstrEncodingStyle),
                                             false); // inserted at this node, not rcvd in msg
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetHeaderElemLiteral(BSTR bstrNamespaceURI, BSTR bstrName, BSTR *pbstrLiteralXML, VARIANT_BOOL *pResult)
{
	wstring wstrLiteralXML;
	bool bRtn = m_pSOAPMsg->GetHeaderElemLit(   wstring(bstrNamespaceURI),
												wstring(bstrName),
												wstrLiteralXML);
    if (bRtn == true)
    {
	    *pbstrLiteralXML = SysAllocString(wstrLiteralXML.c_str());
    }
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetNumHeaderElemsLiteral(long *plNumber)
{
	*plNumber = m_pSOAPMsg->GetNumHeaderElemsLit();
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetFirstHeaderElemLiteral(BSTR *pbstrNamespaceURI, BSTR *pbstrName, BSTR *pbstrLiteralXML, VARIANT_BOOL *pbMustUnderstand, BSTR *pbstrActorURI, BSTR *pbstrEncodingStyle, long *plPosition, VARIANT_BOOL *pResult)
{
	long lPos;
    WMSOAPHeaderMsgElementLit *pHdrElemLit;
	bool bRtn = m_pSOAPMsg->GetFirstHeaderElemLit(  &pHdrElemLit,
													lPos);
	if (bRtn == true)
	{
        *pbstrLiteralXML = SysAllocString(pHdrElemLit->m_wstrLiteralXML.c_str());
        *pbstrNamespaceURI = SysAllocString(pHdrElemLit->m_wstrNamespaceURI.c_str());
        *pbstrName = SysAllocString(pHdrElemLit->m_wstrName.c_str());
        *pbMustUnderstand = (pHdrElemLit->m_bMustUnderstand == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrActorURI = SysAllocString(pHdrElemLit->m_wstrActor.c_str());
        *pbstrEncodingStyle = SysAllocString(pHdrElemLit->m_wstrEncodingStyle.c_str());
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetNextHeaderElemLiteral(BSTR *pbstrNamespaceURI, BSTR *pbstrName, BSTR *pbstrLiteralXML, VARIANT_BOOL *pbMustUnderstand, BSTR *pbstrActorURI, BSTR *pbstrEncodingStyle, long *plPosition, VARIANT_BOOL *pResult)
{
    WMSOAPHeaderMsgElementLit *pHdrElemLit;
	long lPos = *plPosition;
	bool bRtn = m_pSOAPMsg->GetNextHeaderElemLit(   &pHdrElemLit,
													lPos);
	if (bRtn == true)
	{
        *pbstrLiteralXML = SysAllocString(pHdrElemLit->m_wstrLiteralXML.c_str());
        *pbstrNamespaceURI = SysAllocString(pHdrElemLit->m_wstrNamespaceURI.c_str());
        *pbstrName = SysAllocString(pHdrElemLit->m_wstrName.c_str());
        *pbMustUnderstand = (pHdrElemLit->m_bMustUnderstand == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrActorURI = SysAllocString(pHdrElemLit->m_wstrActor.c_str());
        *pbstrEncodingStyle = SysAllocString(pHdrElemLit->m_wstrEncodingStyle.c_str());
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::SetBodyElemLiteral(BSTR bstrLiteralXML, BSTR bstrEncodingStyle, VARIANT_BOOL *pResult)
{
	bool bRtn = m_pSOAPMsg->SetBodyElemLit(wstring(bstrLiteralXML), wstring(bstrEncodingStyle));
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetBodyElemLiteral(BSTR *pbstrLiteralXML, VARIANT_BOOL *pResult)
{
	wstring wstrLiteralXML;
	bool bRtn = m_pSOAPMsg->GetBodyElemLit(wstrLiteralXML);
    if (bRtn == true)
    {
	    *pbstrLiteralXML = SysAllocString(wstrLiteralXML.c_str());
    }
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::IsNoContentResponse(VARIANT_BOOL *pResult)
{
	*pResult = (m_pSOAPMsg->IsNoContentResponse() == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::SetNoContentResponse(VARIANT_BOOL bValue)
{
	m_pSOAPMsg->SetNoContentResponse(bValue == VARIANT_TRUE ? true : false);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetPortAddress(BSTR *pbstrAddress)
{
	wstring wstrTemp;
	m_pSOAPMsg->GetPortAddress(wstrTemp);
	*pbstrAddress = SysAllocString(wstrTemp.c_str());
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::AddDIMEAttachmentReq(BSTR bstrId, BSTR bstrType, long TNF, IUnknown *pIUnknown, VARIANT Options, VARIANT_BOOL *pResult)
{
	SAFEARRAY *pArray = NULL;
	if ((Options.vt & VT_TYPEMASK) & (VT_ARRAY | VT_UI1))
	{
		pArray = Options.parray;
	}
	bool bRtn = m_pSOAPMsg->AddDIMEAttachmentReq(wstring(bstrId), wstring(bstrType), TNF, pIUnknown, pArray);
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::AddDIMEAttachmentResp(BSTR bstrId, BSTR bstrType, long TNF, IUnknown *pIUnknown, VARIANT Options, VARIANT_BOOL *pResult)
{
	SAFEARRAY *pArray = NULL;
	if ((Options.vt & VT_TYPEMASK) & (VT_ARRAY | VT_UI1))
	{
		pArray = Options.parray;
	}
	bool bRtn = m_pSOAPMsg->AddDIMEAttachmentResp(wstring(bstrId), wstring(bstrType), TNF, pIUnknown, pArray);
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetFirstDIMEAttachmentReq(BSTR *pbstrId, BSTR *pbstrType, long *pTNF, IUnknown **ppIUnknown, VARIANT *Options, long *plPosition, VARIANT_BOOL *pResult)
{
	wstring wstrId, wstrType;
	long lPos, lTNF;
	SAFEARRAY *pArray = NULL;
	bool bRtn = m_pSOAPMsg->GetFirstDIMEAttachmentReq(  wstrId,
														wstrType,
														lTNF,
														ppIUnknown,
														&pArray,
														lPos);
	if (bRtn == true)
	{
		*pbstrId = SysAllocString(wstrId.c_str());
		*pbstrType = SysAllocString(wstrType.c_str());
		*pTNF = lTNF;
		if (Options->vt & VT_BYREF)
		{
			*(Options->pparray) = pArray;
		}
		else
		{
			Options->parray = pArray;
		}
		Options->vt |= (VT_UI1 | VT_ARRAY);
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetNextDIMEAttachmentReq(BSTR *pbstrId, BSTR *pbstrType, long *pTNF, IUnknown **ppIUnknown, VARIANT *Options, long *plPosition, VARIANT_BOOL *pResult)
{
	long lPos = *plPosition;
	wstring wstrId, wstrType;
	long lTNF;
	SAFEARRAY *pArray = NULL;
	bool bRtn = m_pSOAPMsg->GetNextDIMEAttachmentReq(   wstrId,
														wstrType,
														lTNF,
														ppIUnknown,
														&pArray,
														lPos);
	if (bRtn == true)
	{
		*pbstrId = SysAllocString(wstrId.c_str());
		*pbstrType = SysAllocString(wstrType.c_str());
		*pTNF = lTNF;
		if (Options->vt & VT_BYREF)
		{
			*(Options->pparray) = pArray;
		}
		else
		{
			Options->parray = pArray;
		}
		Options->vt |= (VT_UI1 | VT_ARRAY);
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetFirstDIMEAttachmentResp(BSTR *pbstrId, BSTR *pbstrType, long *pTNF, IUnknown **ppIUnknown, VARIANT *Options, long *plPosition, VARIANT_BOOL *pResult)
{
	wstring wstrId, wstrType;
	long lPos, lTNF;
	SAFEARRAY *pArray = NULL;
	bool bRtn = m_pSOAPMsg->GetFirstDIMEAttachmentResp( wstrId,
														wstrType,
														lTNF,
														ppIUnknown,
														&pArray,
														lPos);
	if (bRtn == true)
	{
		*pbstrId = SysAllocString(wstrId.c_str());
		*pbstrType = SysAllocString(wstrType.c_str());
		*pTNF = lTNF;
		if (Options->vt & VT_BYREF)
		{
			*(Options->pparray) = pArray;
		}
		else
		{
			Options->parray = pArray;
		}
		Options->vt |= (VT_UI1 | VT_ARRAY);
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetNextDIMEAttachmentResp(BSTR *pbstrId, BSTR *pbstrType, long *pTNF, IUnknown **ppIUnknown, VARIANT *Options, long *plPosition, VARIANT_BOOL *pResult)
{
	long lPos = *plPosition;
	wstring wstrId, wstrType;
	long lTNF;
	SAFEARRAY *pArray = NULL;
	bool bRtn = m_pSOAPMsg->GetNextDIMEAttachmentResp(  wstrId,
														wstrType,
														lTNF,
														ppIUnknown,
														&pArray,
														lPos);
	if (bRtn == true)
	{
		*pbstrId = SysAllocString(wstrId.c_str());
		*pbstrType = SysAllocString(wstrType.c_str());
		*pTNF = lTNF;
		if (Options->vt & VT_BYREF)
		{
			*(Options->pparray) = pArray;
		}
		else
		{
			Options->parray = pArray;
		}
		Options->vt |= (VT_UI1 | VT_ARRAY);
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetDIMEAttachmentReq(BSTR bstrId, BSTR *pbstrType, long *pTNF, IUnknown **ppIUnknown, VARIANT *Options, VARIANT_BOOL *pResult)
{
	wstring wstrType;
	long lTNF;
	SAFEARRAY *pArray = NULL;
	bool bRtn = m_pSOAPMsg->GetDIMEAttachmentReq(   wstring(bstrId),
													wstrType,
													lTNF,
													ppIUnknown,
													&pArray);
	if (bRtn == true)
	{
		*pbstrType = SysAllocString(wstrType.c_str());
		*pTNF = lTNF;
		if (Options->vt & VT_BYREF)
		{
			*(Options->pparray) = pArray;
		}
		else
		{
			Options->parray = pArray;
		}
		Options->vt |= (VT_UI1 | VT_ARRAY);
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetDIMEAttachmentResp(BSTR bstrId, BSTR *pbstrType, long *pTNF, IUnknown **ppIUnknown, VARIANT *Options, VARIANT_BOOL *pResult)
{
	wstring wstrType;
	long lTNF;
	SAFEARRAY *pArray = NULL;
	bool bRtn = m_pSOAPMsg->GetDIMEAttachmentResp(  wstring(bstrId),
													wstrType,
													lTNF,
													ppIUnknown,
													&pArray);
	if (bRtn == true)
	{
		*pbstrType = SysAllocString(wstrType.c_str());
		*pTNF = lTNF;
		if (Options->vt & VT_BYREF)
		{
			*(Options->pparray) = pArray;
		}
		else
		{
			Options->parray = pArray;
		}
		Options->vt |= (VT_UI1 | VT_ARRAY);
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetNumReqAttachments(long *pNbr)
{
	*pNbr = m_pSOAPMsg->GetNumReqAttachments();

	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetNumRespAttachments(long *pNbr)
{
	*pNbr = m_pSOAPMsg->GetNumRespAttachments();

	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetSOAPVersion(long *pVersion)
{
	*pVersion = m_pSOAPMsg->GetSOAPVersion();

    return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::SetSOAPVersion(LONG lVersion)
{
    m_pSOAPMsg->SetSOAPVersion(lVersion);

    return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::SetRoles(VARIANT varRoles, VARIANT_BOOL *pResult)
{
    *pResult = VARIANT_FALSE;
    if (!(varRoles.vt & (VT_VARIANT | VT_ARRAY)))
    {
	    return S_OK;
    }
	SAFEARRAY *pArray = varRoles.parray;
    if (pArray->cDims != 1)
    {
	    return S_OK;
    }
    list<wstring> listRoles;
	long arrIndex[1];
	for (unsigned int i = pArray->rgsabound[0].lLbound;
			i < (pArray->rgsabound[0].lLbound + pArray->rgsabound[0].cElements);
			i++)
	{
		arrIndex[0] = i;
		// get pointer to struct object
		VARIANT *pVar = NULL;
		SafeArrayPtrOfIndex(pArray, arrIndex, (void **)&pVar);
        listRoles.push_back(wstring(pVar->bstrVal));
    }
	bool bRtn = m_pSOAPMsg->SetRoles(listRoles);
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetRoles(VARIANT *pvarRoles)
{
    list<wstring> listRoles;
    m_pSOAPMsg->GetRoles(listRoles);
    // store in SAFEARRAY
	SAFEARRAYBOUND Bounds[1];
	Bounds[0].lLbound = 0;
	Bounds[0].cElements = listRoles.size();
	SAFEARRAY *pArray = SafeArrayCreate(VT_VARIANT, 1, Bounds);
    pvarRoles->parray = pArray;
    pvarRoles->vt = (VT_ARRAY | VT_VARIANT);
    _variant_t varItem;
    long arrIndex[1];
    int counter = 0;
    list<wstring>::iterator iL;
    for (iL = listRoles.begin();
        iL != listRoles.end();
        iL++)
    {
        varItem = (*iL).c_str();
		arrIndex[0] = counter++;
		// put it away
		SafeArrayPutElement(pArray, arrIndex, &varItem);
    }
    return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetMUHeaderBlocks(VARIANT *pvarBlocks)
{
    list<wstring> listLocalNames, listNamespaces;
	m_pSOAPMsg->GetMUHeaderBlocks(listNamespaces, listLocalNames);
	// create SAFEARRAY
	const long lNumDims = 2;
	SAFEARRAYBOUND Bounds[lNumDims];
	// rightmost dimension (cols) will go in Bounds[0]
	Bounds[0].lLbound = 0;
	Bounds[0].cElements = 2;
	// leftmost dimension (rows) will go in Bounds[1]
	Bounds[1].lLbound = 0;
	Bounds[1].cElements = listLocalNames.size();

	SAFEARRAY *pArray = SafeArrayCreate(VT_VARIANT, lNumDims, &Bounds[0]);
	if (pArray == NULL)
	{
		return E_FAIL;
	}
	pvarBlocks->parray = pArray;
	pvarBlocks->vt = (VT_VARIANT | VT_ARRAY);
	// set up index for insertion
	long *arrIndex = new long[lNumDims];
	// read out data
	list<wstring>::iterator iL1, iL2;
	long lCounter = 0;
	_variant_t varTemp;
	// array format: [rows][cols]
	for (iL1 = listNamespaces.begin(), iL2 = listLocalNames.begin();
			iL1 != listNamespaces.end() && iL2 != listLocalNames.end();
            iL1++, iL2++)
	{
		// leftmost dimension (rows) is arrIndex[1]
		arrIndex[1] = lCounter++;
		// rightmost dimension (cols) is arrIndex[0]
		arrIndex[0] = 0;
		// namespace
		varTemp = (*iL1).c_str();
		SafeArrayPutElement(pArray, arrIndex, &varTemp);
		// local name
		arrIndex[0] = 1;
		varTemp = (*iL2).c_str();
		SafeArrayPutElement(pArray, arrIndex, &varTemp);
	}
    return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::AddHeaderElem12(BSTR bstrNamespaceURI, BSTR bstrName, VARIANT varContent, VARIANT_BOOL bMustUnderstand, BSTR bstrRoleURI, VARIANT_BOOL bRelay, VARIANT_BOOL *pResult)
{
	bool bRtn = m_pSOAPMsg->AddHeaderElem(wstring(bstrNamespaceURI),
										 wstring(bstrName),
										 _variant_t(varContent),
										 bMustUnderstand == VARIANT_TRUE ? true : false,
										 wstring(bstrRoleURI),
                                         bRelay == VARIANT_TRUE ? true : false,
                                         false); // inserted at this node, not rcvd in msg
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetFirstHeaderElem12(BSTR *pbstrNamespaceURI, BSTR *pbstrName, VARIANT *pvarContent, VARIANT_BOOL *pbMustUnderstand, BSTR *pbstrRoleURI, VARIANT_BOOL *pbRelay, long *plPosition, VARIANT_BOOL *pResult)
{
    long lPos;
    WMSOAPHeaderMsgElement *pHdrElem;
	bool bRtn = m_pSOAPMsg->GetFirstHeaderElem( &pHdrElem,
												lPos);
	if (bRtn == true)
	{
        *pbstrNamespaceURI = SysAllocString(pHdrElem->m_wstrNamespaceURI.c_str());
        *pbstrName = SysAllocString(pHdrElem->m_wstrName.c_str());
        *pbMustUnderstand = (pHdrElem->m_bMustUnderstand == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrRoleURI = SysAllocString(pHdrElem->m_wstrActor.c_str());
        *pbRelay = (pHdrElem->m_bRelay == true ? VARIANT_TRUE : VARIANT_FALSE);
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
    return VariantCopy(pvarContent, &pHdrElem->m_varContent);
}

STDMETHODIMP CwmsoapmsgObj::GetNextHeaderElem12(BSTR *pbstrNamespaceURI, BSTR *pbstrName, VARIANT *pvarContent, VARIANT_BOOL *pbMustUnderstand, BSTR *pbstrRoleURI, VARIANT_BOOL *pbRelay, long *plPosition, VARIANT_BOOL *pResult)
{
	long lPos = *plPosition;
    WMSOAPHeaderMsgElement *pHdrElem;
	bool bRtn = m_pSOAPMsg->GetNextHeaderElem(  &pHdrElem,
												lPos);

	if (bRtn == true)
	{
        *pbstrNamespaceURI = SysAllocString(pHdrElem->m_wstrNamespaceURI.c_str());
        *pbstrName = SysAllocString(pHdrElem->m_wstrName.c_str());
        *pbMustUnderstand = (pHdrElem->m_bMustUnderstand == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrRoleURI = SysAllocString(pHdrElem->m_wstrActor.c_str());
        *pbRelay = (pHdrElem->m_bRelay == true ? VARIANT_TRUE : VARIANT_FALSE);
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return VariantCopy(pvarContent, &pHdrElem->m_varContent);
}

STDMETHODIMP CwmsoapmsgObj::AddHeaderElemLiteral12(BSTR bstrNamespaceURI, BSTR bstrName, BSTR bstrLiteralXML, VARIANT_BOOL bMustUnderstand, BSTR bstrRoleURI, VARIANT_BOOL bRelay, BSTR bstrEncodingStyle, VARIANT_BOOL *pResult)
{
	bool bRtn = m_pSOAPMsg->AddHeaderElemLit(wstring(bstrNamespaceURI),
											 wstring(bstrName),
											 wstring(bstrLiteralXML),
											 bMustUnderstand == VARIANT_TRUE ? true : false,
											 wstring(bstrRoleURI),
                                             bRelay == VARIANT_TRUE ? true : false,
											 wstring(bstrEncodingStyle),
                                             false); // inserted at this node, not rcvd in msg
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetFirstHeaderElemLiteral12(BSTR *pbstrNamespaceURI, BSTR *pbstrName, BSTR *pbstrLiteralXML, VARIANT_BOOL *pbMustUnderstand, BSTR *pbstrRoleURI, VARIANT_BOOL *pbRelay, BSTR *pbstrEncodingStyle, long *plPosition, VARIANT_BOOL *pResult)
{
	long lPos;
    WMSOAPHeaderMsgElementLit *pHdrElemLit;
	bool bRtn = m_pSOAPMsg->GetFirstHeaderElemLit(  &pHdrElemLit,
													lPos);
	if (bRtn == true)
	{
        *pbstrLiteralXML = SysAllocString(pHdrElemLit->m_wstrLiteralXML.c_str());
        *pbstrNamespaceURI = SysAllocString(pHdrElemLit->m_wstrNamespaceURI.c_str());
        *pbstrName = SysAllocString(pHdrElemLit->m_wstrName.c_str());
        *pbMustUnderstand = (pHdrElemLit->m_bMustUnderstand == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrRoleURI = SysAllocString(pHdrElemLit->m_wstrActor.c_str());
        *pbRelay = (pHdrElemLit->m_bRelay == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrEncodingStyle = SysAllocString(pHdrElemLit->m_wstrEncodingStyle.c_str());
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetNextHeaderElemLiteral12(BSTR *pbstrNamespaceURI, BSTR *pbstrName, BSTR *pbstrLiteralXML, VARIANT_BOOL *pbMustUnderstand, BSTR *pbstrRoleURI, VARIANT_BOOL *pbRelay, BSTR *pbstrEncodingStyle, long *plPosition, VARIANT_BOOL *pResult)
{
    WMSOAPHeaderMsgElementLit *pHdrElemLit;
	long lPos = *plPosition;
	bool bRtn = m_pSOAPMsg->GetNextHeaderElemLit(   &pHdrElemLit,
													lPos);
	if (bRtn == true)
	{
        *pbstrLiteralXML = SysAllocString(pHdrElemLit->m_wstrLiteralXML.c_str());
        *pbstrNamespaceURI = SysAllocString(pHdrElemLit->m_wstrNamespaceURI.c_str());
        *pbstrName = SysAllocString(pHdrElemLit->m_wstrName.c_str());
        *pbMustUnderstand = (pHdrElemLit->m_bMustUnderstand == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrRoleURI = SysAllocString(pHdrElemLit->m_wstrActor.c_str());
        *pbRelay = (pHdrElemLit->m_bRelay == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrEncodingStyle = SysAllocString(pHdrElemLit->m_wstrEncodingStyle.c_str());
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::AddFaultHeaderElem12(BSTR bstrNamespaceURI, BSTR bstrName, VARIANT varContent, VARIANT_BOOL bMustUnderstand, BSTR bstrRoleURI, VARIANT_BOOL bRelay, VARIANT_BOOL *pResult)
{
	bool bRtn = m_pSOAPMsg->AddFaultHeaderElem(  wstring(bstrNamespaceURI),
												 wstring(bstrName),
												 _variant_t(varContent),
												 bMustUnderstand == VARIANT_TRUE ? true : false,
												 wstring(bstrRoleURI),
                                                 bRelay == VARIANT_TRUE ? true : false);
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetFirstFaultHeaderElem12(BSTR *pbstrNamespaceURI, BSTR *pbstrName, VARIANT *pvarContent, VARIANT_BOOL *pbMustUnderstand, BSTR *pbstrRoleURI, VARIANT_BOOL *pbRelay, long *plPosition, VARIANT_BOOL *pResult)
{
	long lPos;
    WMSOAPHeaderMsgElement *pHdrElem;
	bool bRtn = m_pSOAPMsg->GetFirstFaultHeaderElem(&pHdrElem,
													lPos);
	if (bRtn == true)
	{
        *pbstrNamespaceURI = SysAllocString(pHdrElem->m_wstrNamespaceURI.c_str());
        *pbstrName = SysAllocString(pHdrElem->m_wstrName.c_str());
        *pbMustUnderstand = (pHdrElem->m_bMustUnderstand == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrRoleURI = SysAllocString(pHdrElem->m_wstrActor.c_str());
        *pbRelay = (pHdrElem->m_bRelay == true ? VARIANT_TRUE : VARIANT_FALSE);
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return VariantCopy(pvarContent, &pHdrElem->m_varContent);
}

STDMETHODIMP CwmsoapmsgObj::GetNextFaultHeaderElem12(BSTR *pbstrNamespaceURI, BSTR *pbstrName, VARIANT *pvarContent, VARIANT_BOOL *pbMustUnderstand, BSTR *pbstrRoleURI, VARIANT_BOOL *pbRelay, long *plPosition, VARIANT_BOOL *pResult)
{
	long lPos = *plPosition;
    WMSOAPHeaderMsgElement *pHdrElem;
	bool bRtn = m_pSOAPMsg->GetNextFaultHeaderElem( &pHdrElem,
													lPos);
	if (bRtn == true)
	{
        *pbstrNamespaceURI = SysAllocString(pHdrElem->m_wstrNamespaceURI.c_str());
        *pbstrName = SysAllocString(pHdrElem->m_wstrName.c_str());
        *pbMustUnderstand = (pHdrElem->m_bMustUnderstand == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrRoleURI = SysAllocString(pHdrElem->m_wstrActor.c_str());
        *pbRelay = (pHdrElem->m_bRelay == true ? VARIANT_TRUE : VARIANT_FALSE);
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return VariantCopy(pvarContent, &pHdrElem->m_varContent);
}

STDMETHODIMP CwmsoapmsgObj::AddFaultHeaderElemLiteral12(BSTR bstrNamespaceURI, BSTR bstrName, BSTR bstrLiteralXML, VARIANT_BOOL bMustUnderstand, BSTR bstrRoleURI, VARIANT_BOOL bRelay, BSTR bstrEncodingStyle, VARIANT_BOOL *pResult)
{
	bool bRtn = m_pSOAPMsg->AddFaultHeaderElemLit(   wstring(bstrNamespaceURI),
													 wstring(bstrName),
													 wstring(bstrLiteralXML),
													 bMustUnderstand == VARIANT_TRUE ? true : false,
													 wstring(bstrRoleURI),
                                                     false,
													 wstring(bstrEncodingStyle));
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}
	
STDMETHODIMP CwmsoapmsgObj::GetFirstFaultHeaderElemLiteral12(BSTR *pbstrNamespaceURI, BSTR *pbstrName, BSTR *pbstrLiteralXML, VARIANT_BOOL *pbMustUnderstand, BSTR *pbstrRoleURI, VARIANT_BOOL *pbRelay, BSTR *pbstrEncodingStyle, long *plPosition, VARIANT_BOOL *pResult)
{
	long lPos;
    WMSOAPHeaderMsgElementLit *pHdrElemLit;
	bool bRtn = m_pSOAPMsg->GetFirstFaultHeaderElemLit( &pHdrElemLit,
														lPos);
	if (bRtn == true)
	{
        *pbstrLiteralXML = SysAllocString(pHdrElemLit->m_wstrLiteralXML.c_str());
        *pbstrNamespaceURI = SysAllocString(pHdrElemLit->m_wstrNamespaceURI.c_str());
        *pbstrName = SysAllocString(pHdrElemLit->m_wstrName.c_str());
        *pbMustUnderstand = (pHdrElemLit->m_bMustUnderstand == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrRoleURI = SysAllocString(pHdrElemLit->m_wstrActor.c_str());
        *pbRelay = (pHdrElemLit->m_bRelay == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrEncodingStyle = SysAllocString(pHdrElemLit->m_wstrEncodingStyle.c_str());
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

STDMETHODIMP CwmsoapmsgObj::GetNextFaultHeaderElemLiteral12(BSTR *pbstrNamespaceURI, BSTR *pbstrName, BSTR *pbstrLiteralXML,  VARIANT_BOOL *pbMustUnderstand,  BSTR *pbstrRoleURI, VARIANT_BOOL *pbRelay, BSTR *pbstrEncodingStyle, long *plPosition, VARIANT_BOOL *pResult)
{
	long lPos = *plPosition;
    WMSOAPHeaderMsgElementLit *pHdrElemLit;
	bool bRtn = m_pSOAPMsg->GetNextFaultHeaderElemLit(  &pHdrElemLit,
														lPos);
	if (bRtn == true)
	{
        *pbstrLiteralXML = SysAllocString(pHdrElemLit->m_wstrLiteralXML.c_str());
        *pbstrNamespaceURI = SysAllocString(pHdrElemLit->m_wstrNamespaceURI.c_str());
        *pbstrName = SysAllocString(pHdrElemLit->m_wstrName.c_str());
        *pbMustUnderstand = (pHdrElemLit->m_bMustUnderstand == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrRoleURI = SysAllocString(pHdrElemLit->m_wstrActor.c_str());
        *pbRelay = (pHdrElemLit->m_bRelay == true ? VARIANT_TRUE : VARIANT_FALSE);
        *pbstrEncodingStyle = SysAllocString(pHdrElemLit->m_wstrEncodingStyle.c_str());
		*plPosition = lPos;
	}
	*pResult = (bRtn == true ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

