T
Tolga Onbay
class CSampleBasicAuth : public CBasicAuthObject, public IAuthInfo
{
public :
void setUserName()
{
username = L"foo";
password = L"bar";
}
void Init(CAtlHttpClient *pSocket, IAuthInfo *pAuthInfo)
{
CBasicAuthObject::Init( pSocket, pAuthInfo );
}
bool Authenticate(LPCTSTR szAuthTypes, bool bProxy)
{
return CBasicAuthObject::Authenticate( szAuthTypes, bProxy );
}
HRESULT GetPassword(LPTSTR szPwd, DWORD* dwBuffSize)
{
if (CopyCString( password, szPwd, dwBuffSize ))
return S_OK;
return E_FAIL;
}
HRESULT GetUsername(LPTSTR szUid, DWORD* dwBuffSize)
{
if (CopyCString( username, szUid, dwBuffSize ))
return S_OK;
return E_FAIL;
}
HRESULT GetDomain(LPTSTR szDomain, DWORD* dwBuffSize)
{
ATLASSERT(false);
return S_OK;
}
CString username;
CString password;
};
....
void CWSdenemeDlg::OnBnClickedOk()
{
CString strMessage;
CoInitialize(NULL);
CWebService *ws = new CWebService();
ws->CleanupClient();
CAtlHttpClient &httpClient = ws->m_socket;
CSampleBasicAuth authObject;
authObject.setUserName();
httpClient.AddAuthObj(ATL_HTTP_AUTHTYPE_BASIC, &authObject,
&authObject);
bool val = httpClient.NegotiateAuth(true);
WSInputClass in;
in.member = ...
WSOutputClass* out = new WSOutputClass();
HRESULT hr = (HRESULT) ws->process(in, out);
if(FAILED(hr)){
switch(ws->GetClientError( ))
{
case SOAPCLIENT_INITIALIZE_ERROR :
strMessage="SOAPCLIENT_INITIALIZE_ERROR";
break;
case SOAPCLIENT_OUTOFMEMORY :
strMessage="SOAPCLIENT_OUTOFMEMORY";
break;
case SOAPCLIENT_GENERATE_ERROR :
strMessage="SOAPCLIENT_GENERATE_ERROR";
break;
case SOAPCLIENT_CONNECT_ERROR :
strMessage="SOAPCLIENT_CONNECT_ERROR";
break;
case SOAPCLIENT_SEND_ERROR :
strMessage="SOAPCLIENT_SEND_ERROR";
break;
case SOAPCLIENT_SERVER_ERROR :
strMessage="SOAPCLIENT_SERVER_ERROR ";
break;
case SOAPCLIENT_SOAPFAULT :
strMessage="SOAPCLIENT_SOAPFAULT";
break;
case SOAPCLIENT_PARSEFAULT_ERROR :
strMessage="SOAPCLIENT_PARSEFAULT_ERROR";
break;
case SOAPCLIENT_READ_ERROR :
strMessage="SOAPCLIENT_READ_ERROR";
break;
case SOAPCLIENT_PARSE_ERROR :
strMessage="SOAPCLIENT_PARSE_ERROR";
break;
case SOAPCLIENT_SUCCESS :
strMessage="SOAPCLIENT_SUCCESS";
break;
}
MessageBox(strMessage);
}
}
{
public :
void setUserName()
{
username = L"foo";
password = L"bar";
}
void Init(CAtlHttpClient *pSocket, IAuthInfo *pAuthInfo)
{
CBasicAuthObject::Init( pSocket, pAuthInfo );
}
bool Authenticate(LPCTSTR szAuthTypes, bool bProxy)
{
return CBasicAuthObject::Authenticate( szAuthTypes, bProxy );
}
HRESULT GetPassword(LPTSTR szPwd, DWORD* dwBuffSize)
{
if (CopyCString( password, szPwd, dwBuffSize ))
return S_OK;
return E_FAIL;
}
HRESULT GetUsername(LPTSTR szUid, DWORD* dwBuffSize)
{
if (CopyCString( username, szUid, dwBuffSize ))
return S_OK;
return E_FAIL;
}
HRESULT GetDomain(LPTSTR szDomain, DWORD* dwBuffSize)
{
ATLASSERT(false);
return S_OK;
}
CString username;
CString password;
};
....
void CWSdenemeDlg::OnBnClickedOk()
{
CString strMessage;
CoInitialize(NULL);
CWebService *ws = new CWebService();
ws->CleanupClient();
CAtlHttpClient &httpClient = ws->m_socket;
CSampleBasicAuth authObject;
authObject.setUserName();
httpClient.AddAuthObj(ATL_HTTP_AUTHTYPE_BASIC, &authObject,
&authObject);
bool val = httpClient.NegotiateAuth(true);
WSInputClass in;
in.member = ...
WSOutputClass* out = new WSOutputClass();
HRESULT hr = (HRESULT) ws->process(in, out);
if(FAILED(hr)){
switch(ws->GetClientError( ))
{
case SOAPCLIENT_INITIALIZE_ERROR :
strMessage="SOAPCLIENT_INITIALIZE_ERROR";
break;
case SOAPCLIENT_OUTOFMEMORY :
strMessage="SOAPCLIENT_OUTOFMEMORY";
break;
case SOAPCLIENT_GENERATE_ERROR :
strMessage="SOAPCLIENT_GENERATE_ERROR";
break;
case SOAPCLIENT_CONNECT_ERROR :
strMessage="SOAPCLIENT_CONNECT_ERROR";
break;
case SOAPCLIENT_SEND_ERROR :
strMessage="SOAPCLIENT_SEND_ERROR";
break;
case SOAPCLIENT_SERVER_ERROR :
strMessage="SOAPCLIENT_SERVER_ERROR ";
break;
case SOAPCLIENT_SOAPFAULT :
strMessage="SOAPCLIENT_SOAPFAULT";
break;
case SOAPCLIENT_PARSEFAULT_ERROR :
strMessage="SOAPCLIENT_PARSEFAULT_ERROR";
break;
case SOAPCLIENT_READ_ERROR :
strMessage="SOAPCLIENT_READ_ERROR";
break;
case SOAPCLIENT_PARSE_ERROR :
strMessage="SOAPCLIENT_PARSE_ERROR";
break;
case SOAPCLIENT_SUCCESS :
strMessage="SOAPCLIENT_SUCCESS";
break;
}
MessageBox(strMessage);
}
}