// WMDIMEClient.h: interface for the WMDIMEClient class.
//
//////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2002 Robert Cunnings. All rights reserved.
//
// You may copy, modify, distribute or publish this code free of charge.
//
// NO WARRANTY: This software is provided AS IS, without warranty of any kind.
//
//////////////////////////////////////////////////////////////////////
//
// WMDIMEClient class - a SOAP processor for the 'client' side.
// Uses DIME packaging, in accordance with Internet-Draft "WS-Attachments"
// (draft-nielsen-dime-soap-01 June 17, 2002).
// 
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_WMDIMECLIENT_H__94C0E387_9C3D_450D_AFA5_0F73F94CEAE2__INCLUDED_)
#define AFX_WMDIMECLIENT_H__94C0E387_9C3D_450D_AFA5_0F73F94CEAE2__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "WMSOAPHeaderDisp.h"
#include "SOAPAutomationDIMEProxy.h"
#include "WMXMLMessage.h"

class WMDIMEClient  
{
public:
	WMDIMEClient();
	virtual ~WMDIMEClient();

	bool Initialize( const string& strWSDLFileURL,
					 const string& strServiceName,
					 const string& strPortName,
					 const string& strNodeURI,
					 const string& strUserAgent,
					 list<wstring>& listHeaderProcProgIDs,
					 bool bUseExplicitTyping,
                     bool bForceDIMEPackaging,
                     int nSOAPVersion = 0);

	bool Initialize( const string& strWSDLFileURL,
					 const string& strServiceName,
					 const string& strPortName,
					 const string& strNodeURI,
					 const string& strUserAgent,
					 list<wstring>& listHeaderProcProgIDs,
					 bool bUseExplicitTyping,
                     bool bForceDIMEPackaging,
                     const string& strProxyHost,
                     int nProxyPort,
                     int nSOAPVersion = 0);
	
	void Cleanup();

	bool NewMessage();

	bool SetRequestHeaderEntry(	const wstring& wstrNS,
								const wstring& wstrActor,
								const wstring& wstrName,
								_variant_t& varValue,
								bool bMustUnderstand = false);

	bool GetResponseHeaderEntry(const wstring& wstrNS,
								const wstring& wstrName,
								_variant_t& varContent);

	void ClearHeaders();

	bool InvokeSOAPMethod(  const wstring& wstrMethod,
							wstring *arrNames,
							_variant_t *arrArgs,
							int nNumArgs,
							_variant_t& varReturn);

	bool InvokeSOAPMethod(  const string& strHTTPMethod,
                            const wstring& wstrMethod,
							wstring *arrNames,
							_variant_t *arrArgs,
							int nNumArgs,
							_variant_t& varReturn);

	bool InvokeSOAPMethod(  const string& strHTTPMethod,
                            const string& strExtraPath,
                            const wstring& wstrMethod,
							wstring *arrNames,
							_variant_t *arrArgs,
							int nNumArgs,
							_variant_t& varReturn);

	bool InvokeSOAPMethod(  const string& strHTTPMethod,
                            const string& strExtraPath,
                            const string& strQueryString,
                            const wstring& wstrMethod,
							wstring *arrNames,
							_variant_t *arrArgs,
							int nNumArgs,
							_variant_t& varReturn);

	bool IsSOAPFault();
	bool GetSOAPFaultCode(wstring& wstrFaultCode);
	bool GetSOAPFaultCodeNS(wstring& wstrFaultCodeNS);
	bool GetSOAPFaultString(wstring& wstrFaultString);
	bool GetSOAPFaultNode(wstring& wstrFaultNode);
	bool GetFaultDetailEntry(const wstring& wstrNS,
							const wstring& wstrName,
							_variant_t& varContent);
    int GetSOAPVersion() { return m_nSOAPVersion; }
    void UseSOAP12NodeType(bool bValue) { m_bUseSOAP12NodeType = bValue; }

    // request SOAP envelope (outbound)
	const char *GetXMLOut() { return m_AutoProxy.GetXMLOut(); }
	unsigned long GetXMLOutLength() { return m_AutoProxy.GetXMLOutLength(); }
    // response SOAP envelope (inbound)
	const char *GetXMLIn() { return m_AutoProxy.GetXMLIn(); }
	unsigned long GetXMLInLength() { return m_AutoProxy.GetXMLInLength(); }
    // SOAP address - use to override address specified in WSDL doc
    void SetSOAPAddress(const string& strHost, const string& strURI, int nPort)
    {
        m_strHost = strHost;
        m_strSvcURI = strURI;
        m_nPortNbr = nPort;
    }

protected:

	void ReleaseMessage();
	void ReleaseWSDLClient();

	// service info
	wstring m_wstrServiceName;
	wstring m_wstrPortName;
	wstring m_wstrNodeURI;
	wstring m_wstrWSDLFileURL;

	// SOAP message interface ptr
	Iwmsoapmsg2					*m_pIwmsoapMsg;

	// WSDL client interface ptr
	Iwmwsdlclient2				*m_pIwmwsdlclient;

	// header dispatcher
	WMSOAPHeaderDisp			m_HeaderDispatcher;

	// method dispatcher
	WMSOAPAutomationDIMEProxy	m_AutoProxy;

	// request info
	string						m_strSvcURI;
	string						m_strHost;
	string						m_strUserAgent;
	int							m_nPortNbr;

	// header processor progid's
	list<wstring>			    m_listHeaderProcProgIDs;

	// header processing flag
	bool						m_bProcessHeader;

	// explicit typing (xsi:type attribute) in request msg
	bool						m_bUseExplicitTyping;

    // serialize with SOAP 1.2 "nodeType" attributes
	bool					    m_bUseSOAP12NodeType;

	// force DIME packaging of SOAP request messages
	bool						m_bForceDIMEPackaging;

    // SOAP Version
    int                         m_nSOAPVersion;

    // HTTP proxy
    bool                        m_bUseProxy;
    string                      m_strProxyHost;
    int                         m_nProxyPort;
};

#endif // !defined(AFX_WMDIMECLIENT_H__94C0E387_9C3D_450D_AFA5_0F73F94CEAE2__INCLUDED_)
