Web Service Authentication Problem

  • Thread starter Thread starter Tolga Onbay
  • Start date Start date
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);
}

}
 
Sorry, I mistakenly erased the information part.

I want to retrieve information from secured(requires user name and
password) web service. I can connect it with .NET using
NetworkCredentials class. But when I tried it with C++, I cannot even
send the username and password. I analyze the network activity with
Ethereal, the code doesn't send any authentication information. So the
server send HTTP 401 Authectication error back.

I'm searching web since last friday. I read and tried all I found.
What am i doing wrong?

Thanks for your help.
 
I solved the issue. Just added the following line.

httpClient.SetSilentLogonOk(true);

Thanks
 
Back
Top