// SOAPAutomationDIMEProxy.h: interface for the WMSOAPAutomationDIMEProxy 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.
//
//////////////////////////////////////////////////////////////////////
//
// WMSOAPAutomationDIMEProxy class - a proxy for SOAP RPC calls to 
// COM based web services... for use by the 'client'.
// Uses DIME packaging, in accordance with Internet-Draft "WS-Attachments"
// (draft-nielsen-dime-soap-01 June 17, 2002).
// 
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_SOAPAUTOMATIONDIMEPROXY_H__365CA870_4F9C_11D4_9E6C_00105AABC815__INCLUDED_)
#define AFX_SOAPAUTOMATIONDIMEPROXY_H__365CA870_4F9C_11D4_9E6C_00105AABC815__INCLUDED_

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

#include <comdef.h>
#include "DIMERequestSock.h"
#include "DIMEParser.h"

interface Iwmsoapmsg2;

class WMSOAPDIMEProxyFault
{
public:
	WMSOAPDIMEProxyFault(const wchar_t *pwszFaultCode, const wchar_t *pwszFaultString)
	{
		m_wstrFaultCode = pwszFaultCode;
		m_wstrFaultString = pwszFaultString;
	}
	~WMSOAPDIMEProxyFault() {}

	const wchar_t *GetFaultCode() { return m_wstrFaultCode.c_str(); }
	const wchar_t *GetFaultString() { return m_wstrFaultString.c_str(); }

private:
	wstring m_wstrFaultCode;
	wstring m_wstrFaultString;
};


class WMSOAPAutomationDIMEProxy  
{
public:

	WMSOAPAutomationDIMEProxy();
	virtual ~WMSOAPAutomationDIMEProxy();

	int GetHTTPStatus();

	bool InvokeMethod(   const string& strSOAPAction,
                         bool bSOAPActionRequired,
						 const string& strHost,
						 int nPortNbr,
                         const string& strHTTPMethod,
						 const string& strSvcURI,
                         const string& strQueryString,
						 const string& strUserAgent,
						 Iwmsoapmsg2 *pIwmsoapmsg,
                         int nSOAPVersion,
						 bool bForceDIMEPackaging = false);

	// can throw exception (WMSOAPDIMEProxyFault *)
	bool InvokeSOAPMethod(   const string& strSOAPAction,
                             bool bSOAPActionRequired,
							 const string& strHost,
							 int nPortNbr,
                             const string& strHTTPMethod,
							 const string& strSvcURI,
                             const string& strQueryString,
							 const string& strUserAgent,
							 Iwmsoapmsg2 *pIwmsoapmsg,
                             int nSOAPVersion,
							 bool bForceDIMEPackaging);

    // request SOAP envelope (outbound)
	const char *GetXMLOut() { return m_strXMLOut.c_str(); }
	unsigned long GetXMLOutLength() { return m_strXMLOut.length(); }
    // response SOAP envelope (inbound)
	const char *GetXMLIn() { return m_strXMLIn.c_str(); }
	unsigned long GetXMLInLength() { return m_strXMLIn.length(); }
    // HTTP Proxy info
    void SetHttpProxy(const string& strHost, int nPort);

protected:

	// request (outbound) XML buffer
	string				m_strXMLOut;
	// response (inbound) XML buffer
	string				m_strXMLIn;
	// HTTP
	int					m_nHTTPStatus;
	// socket
	WMDIMERequestSock	m_Socket;
	// DIME parser
	DIMEParser			m_DIMEParser;
    // HTTP proxy
    bool                m_bUseProxy;
    string              m_strProxyHost;
    int                 m_nProxyPort;
};

#endif // !defined(AFX_SOAPAUTOMATIONDIMEPROXY_H__365CA870_4F9C_11D4_9E6C_00105AABC815__INCLUDED_)
