📄 httpconnbase.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft shared
// source or premium shared source license agreement under which you licensed
// this source code. If you did not accept the terms of the license agreement,
// you are not authorized to use this source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the SOURCE.RTF on your install media or the root of your tools installation.
// THE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//+----------------------------------------------------------------------------
//
//
// File:
// HttpConnBase.cpp
//
// Contents:
//
// CHttpConnBase class implementation - property set/get code
//
//-----------------------------------------------------------------------------
#include "Headers.h"
#ifdef UNDER_CE
#include "strsafe.h"
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
// Property Map
////////////////////////////////////////////////////////////////////////////////////////////////////
BEGIN_PROPERTY_MAP(CHttpConnBase)
ADD_PROPERTY(CHttpConnBase, VT_BSTR, s_EndPointURL, EndPointURL)
ADD_PROPERTY(CHttpConnBase, VT_I4, s_Timeout, Timeout)
ADD_PROPERTY(CHttpConnBase, VT_BSTR, s_AuthUser, AuthUser)
ADD_PROPERTY(CHttpConnBase, VT_BSTR, s_AuthPassword, AuthPassword)
ADD_PROPERTY(CHttpConnBase, VT_BSTR, s_ProxyUser, ProxyUser)
ADD_PROPERTY(CHttpConnBase, VT_BSTR, s_ProxyPassword, ProxyPassword)
ADD_PROPERTY(CHttpConnBase, VT_BSTR, s_ProxyServer, ProxyServer)
ADD_PROPERTY(CHttpConnBase, VT_I4, s_ProxyPort, ProxyPort)
ADD_PROPERTY(CHttpConnBase, VT_BOOL, s_UseProxy, UseProxy)
ADD_PROPERTY(CHttpConnBase, VT_BOOL, s_UseSSL, UseSSL)
ADD_PROPERTY(CHttpConnBase, VT_BSTR, s_SSLClientCertificateName, SSLClientCertificateName)
ADD_PROPERTY(CHttpConnBase, VT_BSTR, s_SoapAction, SoapAction)
ADD_PROPERTY(CHttpConnBase, VT_BSTR, s_HTTPCharset, HTTPCharset)
END_PROPERTY_MAP(CHttpConnBase)
////////////////////////////////////////////////////////////////////////////////////////////////////
// function: CHttpConnBase::CHttpConnBase()
//
// parameters:
//
// description:
// Constructor
// returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
CHttpConnBase::CHttpConnBase()
: m_dwTimeout(DefaultRequestTimeout),
m_bstrAuthUser(0),
m_bstrAuthPassword(0),
m_bstrProxyUser(0),
m_bstrProxyPassword(0),
m_bstrProxyServer(0),
m_dwProxyPort(0),
m_bUseProxy(false),
m_bUseSSL(false),
m_bstrSSLClientCertificateName(0),
m_bstrSoapAction(0),
m_bstrHTTPCharset(0),
m_State(Disconnected)
{
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// function: CHttpConnBase::~CHttpConnBase()
//
// parameters:
//
// description:
//
// returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
CHttpConnBase::~CHttpConnBase()
{
::SysFreeString(m_bstrAuthUser);
::SysFreeString(m_bstrAuthPassword);
::SysFreeString(m_bstrProxyUser);
::SysFreeString(m_bstrProxyPassword);
::SysFreeString(m_bstrProxyServer);
::SysFreeString(m_bstrSSLClientCertificateName);
::SysFreeString(m_bstrSoapAction);
::SysFreeString(m_bstrHTTPCharset);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// function: CHttpConnBase::get_Property(BSTR bstrPropertyName, VARIANT *pPropertyValue)
//
// parameters:
//
// description:
//
// returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CHttpConnBase::get_Property(BSTR pPropertyName, VARIANT *pPropertyValue)
{
return GET_PROPERTY(pPropertyName, pPropertyValue);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// function: CHttpConnBase::put_Property(BSTR bstrPropertyName, VARIANT PropertyValue)
//
// parameters:
//
// description:
//
// returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CHttpConnBase::put_Property(BSTR pPropertyName, VARIANT PropertyValue)
{
return PUT_PROPERTY(pPropertyName, &PropertyValue);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// function: STDMETHODIMP CHttpConnBase::ConnectWSDL(IWSDLPort *pPort)
//
// parameters:
//
// description:
// Connects the Http connector (reads the settings from IWSDLPort)
// returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CHttpConnBase::ConnectWSDL(IWSDLPort *pPort)
{
HRESULT hr = S_OK;
switch (m_State)
{
case Reconnect:
Disconnect();
ASSERT(m_State == Disconnected);
case Connected:
case Disconnected:
break;
case Message:
return E_INVALIDARG;
case Sent:
break;
default:
ASSERT(FALSE);
}
m_WsdlPort = pPort;
CHK(ReadPortSettings(pPort));
hr = S_OK;
Cleanup:
return hr;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// function: STDMETHODIMP CHttpConnBase::Reset()
//
// parameters:
//
// description:
// Resets the connector
// returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CHttpConnBase::Reset()
{
switch (m_State)
{
case Message:
case Sent:
if (SUCCEEDED(AbortMessage()))
{
m_State = Connected;
break;
}
else if (SUCCEEDED(ShutdownConnection()))
{
m_State = Disconnected;
break;
}
m_State = Error;
case Error:
ClearError();
break;
case Reconnect:
case Connected:
case Disconnected:
break;
}
ClearError();
EmptyBuffers();
return S_OK;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
// function: STDMETHODIMP CHttpConnBase::BeginMessageWSDL(IWSDLOperation *pOperation)
//
// parameters:
//
// description:
//
// returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CHttpConnBase::BeginMessageWSDL(IWSDLOperation *pOperation)
{
HRESULT hr = S_OK;
switch (m_State)
{
case Reconnect:
Disconnect();
ASSERT(m_State == Disconnected);
// fall through
case Disconnected:
CHK(EstablishConnection());
m_State = Connected;
// fall through
case Connected:
#if !defined UNDER_CE && defined _DEBUG
ASSERT(IsConnected());
#endif
break;
case Message:
hr = E_INVALIDARG;
goto Cleanup;
case Sent:
break;
}
if (pOperation)
{
CHK(GetSoapAction(pOperation));
}
m_State = Message;
hr = S_OK;
Cleanup:
return hr;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// function: STDMETHODIMP CHttpConnBase::EndMessage()
//
// parameters:
//
// description:
// Finishes construction of message and sends it to the endpoint
// returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CHttpConnBase::EndMessage()
{
if (m_State != Message)
{
return E_INVALIDARG;
}
HRESULT hr = S_OK;
CHK(SendRequest());
m_State = Sent;
CHK(ReceiveResponse());
Cleanup:
return hr;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CHttpConnBase::ReadPortSetting(IWSDLPort *pPort)
//
// parameters:
//
// description:
//
// returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CHttpConnBase::ReadPortSettings(IWSDLPort *pPort)
{
HRESULT hr = S_OK;
BSTR address = 0;
if (pPort != 0)
{
CAutoBSTR bindStyle;
CAutoBSTR transport;
CHK(pPort->get_bindStyle(& bindStyle));
CHK(pPort->get_transport(& transport));
CHK(pPort->get_address(& address));
CHK(PutEndPointURL(address));
}
Cleanup:
::SysFreeString(address);
return hr;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CHttpConnBase::GetSoapAction(IWSDLOperation *pOperation)
//
// parameters:
//
// description:
//
// returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CHttpConnBase::GetSoapAction(IWSDLOperation *pOperation)
{
HRESULT hr = S_OK;
BSTR bstrSoapAction = 0;
if (! pOperation)
{
goto Cleanup;
}
CHK(pOperation->get_soapAction(&bstrSoapAction));
CHK(::FreeAndStoreBSTR(m_bstrSoapAction, bstrSoapAction));
bstrSoapAction = 0;
hr = S_OK;
Cleanup:
::SysFreeString(bstrSoapAction);
return hr;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CHttpConnBase::Disconnect()
//
// parameters:
//
// description:
//
// returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CHttpConnBase::Disconnect()
{
ShutdownConnection();
ClearError();
EmptyBuffers();
m_State = Disconnected;
return S_OK;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// function: STDMETHODIMP CHttpConnBase::ReceiveResponse()
//
// parameters:
//
// description:
// Default response reception code
// returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CHttpConnBase::ReceiveResponse()
{
return S_OK;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// function: STDMETHODIMP CHttpConnBase::AbortMessage()
//
// parameters:
//
// description:
// Attempt to abort the sent message
// returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CHttpConnBase::AbortMessage()
{
return E_FAIL;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// function: STDMETHODIMP CHttpConnBase::EmptyBuffers()
//
// parameters:
//
// description:
// Empty input and output message buffers
// returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CHttpConnBase::EmptyBuffers()
{
return S_OK;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// function: STDMETHODIMP CHttpConnBase::ClearError()
//
// parameters:
//
// description:
// Clears any errors cached in the connector and message buffers
// returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CHttpConnBase::ClearError()
{
return S_OK;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CHttpConnBase::get_EndPointURL(VARIANT *pVal)
//
// parameters:
//
// description:
//
// returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CHttpConnBase::get_EndPointURL(VARIANT *pVal)
{
ASSERT(pVal != 0 && V_VT(pVal) == VT_EMPTY);
HRESULT hr = S_OK;
CHK(GetEndPointURL(&V_BSTR(pVal)));
V_VT(pVal) = VT_BSTR;
Cleanup:
return hr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -