// DimeDocClient.h
//
//////////////////////////////////////////////////////////////////////
//
// 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.
//
//////////////////////////////////////////////////////////////////////
//
// WMDimeDocClient class - a class implementing an HTTP client
// for sending SOAP messages using DIME packaging per the WS-Attachments spec
// found at http://www.ietf.org/internet-drafts/draft-nielsen-dime-soap-01.txt
// Uses the "document/literal" SOAP messaging convention.
// 
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DIMEDOCCLIENT_H__CE664AFE_9841_4FCF_9368_37A155603AB9__INCLUDED_)
#define AFX_DIMEDOCCLIENT_H__CE664AFE_9841_4FCF_9368_37A155603AB9__INCLUDED_

#include "soapdocmessage.h"
#include "DIMEParser.h"

interface Iwmwsdlclient2;

class WMDimeDocClient : public DIMEParser
{
public:
    WMDimeDocClient(void);
    ~WMDimeDocClient(void);

	int GetHTTPStatus() { return m_nHTTPStatus; }
	const wstring& GetErrorMsg() { return m_wstrErrorMsg; }
    int GetSOAPVersion() { return m_nSOAPVersion; }
    void SetSOAPVersion(int nSOAPVersion) { m_nSOAPVersion = nSOAPVersion; }

    bool Initialize(const wstring& wstrWSDLFileURL,
                    const wstring& wstrServiceName,
                    const wstring& wstrPortName,
                    const wstring& wstrUserAgent,
                    bool bForceDIMEPackaging,
                    unsigned long ulRecordSize = 4096);

    bool SetHttpProxy(  const string& strProxyHost,
                        int nProxyPort);

	bool DoOperation(   const wstring& wstrOperation);

	bool DoOperation(   const wstring& wstrOperation,
                        const string& strHTTPMethod);

	bool DoOperation(   const wstring& wstrOperation,
                        const string& strHTTPMethod,
                        const string& strExtraPath);

    bool DoOperation(   const wstring& wstrOperation,
                        const string& strHTTPMethod,
                        const string& strExtraPath,
                        const string& strQueryString);

    const string& GetRequestXML() { return m_strRequestXML; }
    const string& GetResponseXML() { return m_strResponseXML; }

    WMSOAPDocMessage& GetRequestMsg() { return m_RequestMsg; }
    WMSOAPDocMessage& GetResponseMsg() { return m_ResponseMsg; }

    bool IsDIMEResponse() { return m_bIsDIMEResponse; }
    DIMEPayload *GetPayload(const wstring& wstrId);

    // 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:

    bool ReadWSDLDocument(  const wstring& wstrWSDLFileURL,
                            const wstring& wstrServiceName,
                            const wstring& wstrPortName);

    //  HTTP protocol
    string                  m_strHost;
    string                  m_strSvcURI;
    int                     m_nPortNbr;
    string                  m_strUserAgent;
    // HTTP proxy
    bool                    m_bUseProxy;
    string                  m_strProxyHost;
    int                     m_nProxyPort;

    bool                    m_bInitialized;
	// force DIME packaging of SOAP request messages
	bool					m_bForceDIMEPackaging;
    // SOAP version per WSDL
    int                     m_nSOAPVersion;
    // flag indicating response msg type
    bool                    m_bIsDIMEResponse;
    // DIME record size when serializing
    unsigned long           m_ulRecordSize;
    // WSDL client
	Iwmwsdlclient2           *m_pIwmwsdlclient;
	// request XML buffer
	string		            m_strRequestXML;
	// response XML buffer
	string		            m_strResponseXML;
	// HTTP Response status 
	int			            m_nHTTPStatus;
	// error message
	wstring		            m_wstrErrorMsg;
    // request msg
    WMSOAPDocMessage        m_RequestMsg;
    // response msg
    WMSOAPDocMessage        m_ResponseMsg;
};

#endif // !defined(AFX_DIMEDOCCLIENT_H__CE664AFE_9841_4FCF_9368_37A155603AB9__INCLUDED_)
