// soap12testhdrrpcObj.cpp : Implementation of Csoap12testhdrrpcObj

#include "stdafx.h"
#include "soap12testhdrrpcObj.h"
#include <comdef.h>

#include "..\wmsoapmsg\wmsoapmsg_i.c"
#include "..\wmsoapmsg\wmsoapmsg.h"

// Csoap12testhdrrpcObj

static wchar_t *g_pwszHeaderNS = L"http://example.org/ts-tests";

// CinteropechohdrObj

STDMETHODIMP Csoap12testhdrrpcObj::OnProcessHeader(VARIANT SOAPMsgInterface, VARIANT_BOOL *pResult)
{
	// get interface ptr
	IDispatch *pIDispatch = SOAPMsgInterface.pdispVal;
	Iwmsoapmsg2 *pIwmsoapmsg;
	HRESULT hRes = pIDispatch->QueryInterface(IID_Iwmsoapmsg2, (void **)&pIwmsoapmsg);
	if (hRes != S_OK)
	{
		// trouble
		*pResult = VARIANT_FALSE;
		return S_OK;
	}
	// ok
	*pResult = VARIANT_TRUE;
	VARIANT_BOOL bResult;
	pIwmsoapmsg->IsRequestPhase(&bResult);
	// check message phase
	if (bResult == VARIANT_FALSE)
	{
		// this is response phase... do nothing for purposes of test.
	    pIwmsoapmsg->Release();
		return S_OK;
	}
    // request phase... do nothing for purposes of test.
	pIwmsoapmsg->Release();
	return S_OK;
}

STDMETHODIMP Csoap12testhdrrpcObj::OnTestMUHeaderBlock(BSTR bstrNamespace, BSTR bstrLocalName, VARIANT_BOOL *pResult)
{
    *pResult = VARIANT_FALSE;
    if (wcscmp(bstrNamespace, g_pwszHeaderNS) == 0)
    {
        if (wcscmp(bstrLocalName, L"DataHolder") == 0)
        {
            *pResult = VARIANT_TRUE;
            return S_OK;
        }
    }
    return S_OK;
}

