// SOAPAutomationProxy.h: interface for the WMSOAPAutomationProxy class.
//
//////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000 - 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.
//
//////////////////////////////////////////////////////////////////////
//
// WMSOAPAutomationProxy class - a proxy for SOAP RPC calls to 
// COM based web services... for use by the 'client'.
// 
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_SOAPAUTOMATIONPROXY_H__365CA870_4F9C_11D4_9E6C_00105AABC815__INCLUDED_)
#define AFX_SOAPAUTOMATIONPROXY_H__365CA870_4F9C_11D4_9E6C_00105AABC815__INCLUDED_

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

#include <comdef.h>
#include "HTTPWinsocket.h"
interface Iwmsoapmsg2;

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

	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 WMSOAPAutomationProxy  
{
public:

	WMSOAPAutomationProxy();
	virtual ~WMSOAPAutomationProxy();

	int GetHTTPStatus();

	const char *GetXMLOut() { return m_strXMLOut.c_str(); }
	unsigned long GetXMLOutLength() { return m_strXMLOut.length(); }
	const char *GetXMLIn() { return m_Socket.GetContent(); }
	unsigned long GetXMLInLength() { return m_Socket.GetContentLength(); }
    // HTTP Proxy info
    void SetHttpProxy(const string& strHost, int nPort);

	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);

	// can throw exception (WMSOAPProxyFault *)
	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);
protected:

	// outbound XML buffer
	string				m_strXMLOut;
	// HTTP
	int					m_nHTTPStatus;
	// socket
	WMHTTPRequestSock	m_Socket;
    // HTTP proxy
    bool                m_bUseProxy;
    string              m_strProxyHost;
    int                 m_nProxyPort;
};

#endif // !defined(AFX_SOAPAUTOMATIONPROXY_H__365CA870_4F9C_11D4_9E6C_00105AABC815__INCLUDED_)
