VC7, Web Service and Proxy server

  • Thread starter Thread starter Farooque Khan
  • Start date Start date
F

Farooque Khan

Hi,

I am consuing a web service in a VC7 application. I included
the web service as a 'web reference' and calling it's method. Now
I want my application to connect to the web service through a proxy
server. Is this possible? if yes, how?

I have searched but only found proxy use through C# (WebProxy class),
nothing about VC++ 7.

any help would be appreciated.

Thanks,
 
Are you using ATL Server (is your web reference class a derivative of
CSoapSocketClientT<>) ?
If so, then it has a method called SetProxy which takes as arguments the
name of the proxy server and the port

thanks,
bogdan

--
--
--
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Please do not send email directly to this alias. It is for newsgroup
purposes only.

thanks,
bogdan
 
Thanks Bogdan,

Yes I *was* using CSoapSocketClientT derived class for the web reference.
The SetProxy() method of this works fine, but now I have to provide Proxy
Authentication also. I have now derieved my class from CSoapWininetClient
and trying to use the HINTERNET members to provide proxy authentication
information. I am not yet successfull at this. Can you suggest something? Is
my
approach correct?

Thanks,

--

-Farooque Khan
http://farooque.150m.com
 
I think CSoapWininetClient does not support proxy authentication.
A suggestion: you could derive your own class from CSoapWininetClient,
override the ConnectToServer method and copy the old code inside atlsoap.h
for CSoapWininetClient::ConnectToServer, with the modifications highlighted
below:

You will also need to declare 2 new CStringT members, m_strProxyUserName and
m_strProxyPassword, and two new methods to set the values

HRESULT ConnectToServer()
{
if (m_hConnection != NULL)
{
return S_OK;
}

m_hInternet = InternetOpen(
ATLSOAPINET_CLIENT,
m_strProxy.GetLength() ? (INTERNET_OPEN_TYPE_PRECONFIG |
INTERNET_OPEN_TYPE_PROXY) : INTERNET_OPEN_TYPE_PRECONFIG,
m_strProxy.GetLength() ? (LPCTSTR) m_strProxy : NULL,
NULL, 0);

if (m_hInternet != NULL)
{
if (m_dwTimeout != 0)
{
InternetSetOption(m_hInternet, INTERNET_OPTION_CONNECT_TIMEOUT,
&m_dwTimeout, sizeof(m_dwTimeout));
InternetSetOption(m_hInternet, INTERNET_OPTION_RECEIVE_TIMEOUT,
&m_dwTimeout, sizeof(m_dwTimeout));
InternetSetOption(m_hInternet, INTERNET_OPTION_SEND_TIMEOUT,
&m_dwTimeout, sizeof(m_dwTimeout));
InternetSetOption(m_hInternet, INTERNET_OPTION_SEND_TIMEOUT,
&m_dwTimeout, sizeof(m_dwTimeout));


//////////////////////////////////////////////////////// Add these here:
InternetSetOption(m_hInternet, INTERNET_OPTION_PROXY_USERNAME,
m_strProxyUserName.GetBuffer(), m_strProxyUserName.GetLength());
InternetSetOption(m_hInternet, INTERNET_OPTION_PROXY_PASSWORD,
m_strProxyPassword.GetBuffer(), m_strProxyPassword.GetLength());
//////////////////////////////////////////////////////// End Extra:

}
m_hConnection = InternetConnect(m_hInternet, m_url.GetHostName(),
(INTERNET_PORT) m_url.GetPortNumber(), NULL, NULL,
INTERNET_SERVICE_HTTP, INTERNET_FLAG_NO_UI, NULL);

if (m_hConnection != NULL)
{
return S_OK;
}
}
CloseAll();
return E_FAIL;
}


Hope this helps!
--
--
--
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Please do not send email directly to this alias. It is for newsgroup
purposes only.

thanks,
bogdan
 
Bogdan, thanks,
your solution and a few other tweaks worked for me.

Apart from CSoapWininetClient, I also have to use InternetErrorDlg()
to take care of 407-401 response (after HttpSendRequest()).

It works now.

Regards,
--

-Farooque Khan
http://farooque.150m.com
RawDisk - A free raw disk editor
 
Back
Top