|
Introduction
This article explains the how you access a webservice through a Proxy Server.
Using the code
In order to show an example of this, we will use a public web service provided by Google. To use this ws, we need to obtain a Validation Key from Google. Next we defined the search criteria and we display the total of obtained registries.
We use the following libraries :
NetworkCredential Class
Provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication. For a list of all members of this type, see NetworkCredential Members. The NetworkCredential class is a base class that supplies credentials in password-based authentication schemes such as basic, digest, NTLM, and Kerberos. Classes that implement the ICredentials interface, such as the CredentialCache class, return NetworkCredential instances. This class does not support public key-based authentication methods such as SSL client authentication.
WebProxy Class
Contains HTTP proxy settings for the WebRequest class. For a list of all members of this type, see WebProxy Members. The WebProxy class contains the proxy settings that WebRequest instances use to override the proxy settings in GlobalProxySelection. The WebProxy class is the base implementation of the IWebProxyinterface. The Proxy Server IP Adress is 127,0,1,2 and the port is the 80.
The data of the user for the authentication with the proxy are:
User Id: user
Password: pwd
Domain: MyDomain
The following VB.NET code shows an example:
Private Sub btnSearch_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnSearch.Click
Dim s As New Google.GoogleSearchService
Try
Dim strLicenceseKey As String = "google license key"
Dim strSearchTerm As String = "Bruno Capuano"
Dim cr As New System.Net.NetworkCredential("user", "pwd", "MyDomain")
Dim pr As New System.Net.WebProxy("127.0.1.2", 80)
pr.Credentials = cr
s.Proxy = pr
Dim r As Google.GoogleSearchResult = s.doGoogleSearch(strLicenceseKey, _
strSearchTerm, 0, 10, True, "", False, "", "", "")
Dim estResults As Integer = r.estimatedTotalResultsCount
MsgBox(CStr(estResults))
Catch ex As System.Web.Services.Protocols.SoapException
MsgBox(ex.Message)
End Try
End Sub
If you want to use the current user credential you can use the DefaultCredentials Property. The DefaultCredentials property applies only to NTLM, negotiate, and Kerberos-based authentication. Sample :
pr.Credentials = System.Net.CredentialCache.DefaultCredentials
DefaultCredentials represents the system credentials for the current security context in which the application is running. For a client-side application, these are usually the Windows credentials (user name, password, and domain) of the user running the application. For ASP.NET applications, the default credentials are the user credentials of the logged-in user, or the user being impersonated.
Note - The ICredentials instance returned by DefaultCredentials cannot be used to view the user name, password, or domain of the current security context.
Conclusion
This is my first article and a very simple one. Any questions or suggestions are welcome ! Bye !
| You must Sign In to use this message board. |
|
| | Msgs 1 to 25 of 41 (Total in Forum: 41) (Refresh) | FirstPrevNext |
|
|
 |
|
|
Hi , excuse me for my bad English
Consuming a Java Web Service from my company in a windows form with or with the proxy's statements ( Dim lws As New Ser_Aduanas.SiscaWebService Dim lprx As WebProxy = New WebProxy("192.168.21.9", 80) Dim lcrd As NetworkCredential = New NetworkCredential("soportezfd", "Telem@tica") lprx.Credentials = lcrd lws.Proxy = lprx lstr2 = lws.registraManifiestoEnapu("", "", "", "", "", "", "", "", "", "", "", "", "") )
It always expires the time connection (this is the error) "Se ha terminado la conexión: La conexión ha terminado de forma inesperada."
I run the project backwward from a proxy
Please Help Me!!!!!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Bruno, The Proxy Server IP Adress is 127,0,1,2 and the port is the 80. The data of the user for the authentication with the proxy are: User Id: user Password: pwd Domain: MyDomain the proxy server you meant was created by oneself using C#? if that, how can I implement it? Look farword to your feedback.
Arron
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
i am working in donet 1.1 windows application. I am accessing the webservices using proxy settings. If i use winproxy means its working fine.. But if i use CCProxy.. the following code will not work for sometimes.
System.Net.WebProxy WProxy = new System.Net.WebProxy(( ProxyHost,ProxyPort); if((ProxyLogin.Trim().Length > 0) &&(ProxyPassword.Trim().Length > 0)) { System.Net.NetworkCredential cred = new System.Net.NetworkCredential(ProxyLogin,ProxyPassword,ProxyDomain); WProxy.Credentials = cred; }
Its giving the error: The request failed with HTTP status 407 : Unauthorized.
Please give me the solution for this..
Best regards Christy
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I'm trying to access a web address using proxy (Microsoft ISA Server). The authentication is NTLM (using domain in Windows 2000).
My code is :
try { const string proxyHostAndPort = "http://myproxy:8080";
WebProxy webProxy = new WebProxy(proxyHostAndPort, true); webProxy.Credentials = CredentialCache.DefaultCredentials;
WebRequest webRequest = WebRequest.Create("http://www.microsoft.com"); webRequest.Credentials = CredentialCache.DefaultCredentials; webRequest.Proxy = webProxy;
WebResponse webResponse = webRequest.GetResponse(); Stream stream = webResponse.GetResponseStream();
byte[] receivedDataInBytes = new byte[webResponse.ContentLength]; stream.Read(receivedDataInBytes, 0, receivedDataInBytes.Length); string receivedDataInString = Encoding.ASCII.GetString(receivedDataInBytes);
Trace.WriteLine(receivedDataInString); } catch (Exception ex) { Console.WriteLine(ex.ToString()); }
But I get an error (407 - Proxy authentication needed). Are there something wrong in my code ? Thanks.
|
| Sign In·View Thread·PermaLink | 1.75/5 (3 votes) |
|
|
|
 |
|
|
Hi,
the follow code will be run normally in WindowsApplication:
string userName = "a"; string userPass = "a"; string address = "192.168.18.145"; int port = 8080;
WebProxy myproxy = new WebProxy(address , port); NetworkCredential credentials = new NetworkCredential(userName, userPass, null); myproxy.Credentials = credentials;
WebRequest rqt = WebRequest.Create(this.textBox2.Text.Trim()); rqt.Proxy = myproxy; rqt.PreAuthenticate = true;
WebResponse rsp = rqt.GetResponse(); System.IO.Stream stream = rsp.GetResponseStream(); System.IO.StreamReader reader = new System.IO.StreamReader(stream); this.textBox1.Text = reader.ReadToEnd();
stream.Close(); reader.Close();
but in the SmartDeviceApplication,,it will cause the problem : The response did not contain an end of entity mark.
Can you tell me why and how to solve the problem?? Thank you !!
Icerain Lin
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
|
Hi, I am trying to do the following, it seems like it should work, but i am really new to vb.net
Dim IE As InternetExplorer IE = CreateObject("InternetExplorer.Application") IE.Visible = True Dim proxyObject As New System.Net.WebProxy("http://148.244.150.57:80/", True) IE.Proxy = proxyObject IE.Navigate("http://www.whatismyip.com")
basically when it goes to whatismyip.com it should show me the same address as the proxy, currently what is happening is that ie is starting up but then it sort of freezes and no page loads, any ideas how to fix this? (Also is there a way to set the proxy in the ie through vb?)
Thanks, Michael (mike509123 AT hotmail dot com)
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Mike ... I tryed your code in a Sample aplication and the problem seems to be in the line
IE.Proxy = proxyObject
That is beocuse the proxy property of the IExplorer object is no accesible from VbNet. I could not fount the reference to declare a variable as InternetExplorer, so i put the declaration as Object
Dim IE As Object ' InternetExplorer
but in the line of the proxy it throws an Exception.
Bye from Spain
El Bruno
MCP Bruno Capuano Jefe de Desarrollo PECTRA Technology Inc. All the Solutions in One Product +54(351)4245756 - int. 301 www.pectra.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Bueno Bruno, sabes cómo puedo enviar información de una aplicación en VB.NET hacia una página web? No tengo ni la menor idea de cómo hacer esto. Estaba intentando enviar la información por email, pero obtengo una excepción que dice que no se puede acceder al objeto CDO.Message. Agradezco cualquier ayuda sobre cualquiera de los 2 temas.
F chile
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Carlos , buen dia.
Si tu quieres trabajar con una pagina web, deberias crear una aplicacion web, en el caso de microsoft una aplicacion Asp.Net, de esta manera puedes generar tus paginas web. (fijate en http://msdn.microsoft.com/asp.net/[^], que es el sitio oficial de Microsoft para el desarrollo en Asp.Net)
Por otro lado, si quieres enviar datos desde una aplicacion windows a una aplicacion web, puedes utilizar webservices que en el caso de .Net es una tecnologia muy simple. (http://msdn.microsoft.com/webservices/[^])
Por ultimo el envio de mails, utilizando el objeto CDO, solo se puede hacer en el cliente cuando tienes configurada una cuenta de mail y se puede acceder a la misma, en tu caso puede ser que tal vez, que no tengas los permisos suficientes.
Saludos
El Bruno
MCP Bruno Capuano Jefe de Desarrollo PECTRA Technology Inc. All the Solutions in One Product +54(351)4245756 - int. 301 www.pectra.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Estoy consumiendo un webservice que hice pasando por un proxy.. El metodo New de reference.vb me quedo similar a:
Public Sub New() MyBase.New() Dim cr As New System.Net.NetworkCredential("MiUsuario", "MiPass") Dim pr As New System.Net.WebProxy("proxy.com", 8080) pr.Credentials = cr Me.Proxy = pr Me.Url = "http://mywebservice/ws.asmx" End Sub
Pero cuando invoco los metodos del webservice me aparece el error: The request failed with HTTP status 417: Expectation Failed.

¿Como puedo solucionar esto?
Damian Brizuela UPS
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Damian, buen dia.
Una de las opciones, ya que el error es el 417 es que el proxy no sea valido.
Yo probaria con los siguientes cambios,
- utilizaria la IP del proxy en lugar del nombre del mismo. - si estas dentro de un dominio, pondria el nombre completo del usuario
por ejemplo :
Dim cr As New System.Net.NetworkCredential("Dominio\MiUsuario", "MiPass") Dim pr As New System.Net.WebProxy("127.0.0.1", 8080)
Esto puede ser una opcion, ya que el error 417 es un error de cliente, como una peticion no autorizada por ejemplo.
Saludos
El Bruno
MCP Bruno Capuano Jefe de Desarrollo PECTRA Technology Inc. All the Solutions in One Product +54(351)4245756 - int. 301 www.pectra.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Gracias por la respuesta Bruno. Al principio yo pensaba que era asi de simple, pero despues de probar eso y de revisar que toda la teoria este bien... segui probando cosas que no funcionaron hasta que en otro foro me pasaron esta info: System.Net.ServicePointManager.Expect100Continue = False
Agregando esa linea en el archivo reference.vb justo antes de invocar los metodos del web service te deja de tirar el error 417.
Quedaria algo asi:
Public Function EjecutarSentencia(ByVal Sentencia As String) As String System.Net.ServicePointManager.Expect100Continue = False Dim results() As Object = Me.Invoke("EjecutarSentencia", New Object() {Sentencia}) Return CType(results(0), String) End Function
Saludos Damian :->
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Bruno, i'm becoming *crazy* with a probleme. * I have a simple WebService, called "HelloWorld" * i access the web server using a proxy (SQUID on linux). * if my proxy does not require authentication, all works fine! * if my proxy REQUIRE authentication, i cannot reach my service and I have a "Time out" error.
-- CODE -----
[..]
' Set proxy credentials (NOTE: Domain is empty..) Dim cr As New System.Net.NetworkCredential("proxyUser", "proxyPWD", "") Dim pr As System.Net.WebProxy
' NOTE: using GetDefaultProxy or setting manually is the same result.. pr = New WebProxy("10.23.0.66", 3128) 'pr = WebProxy.GetDefaultProxy
pr.Credentials = cr service.Proxy = pr service.timeout = 10000 '10 seconds timeout
result = service.helloWord() ' <------ TIMEOUT ERROR!!
-- END CODE ----
Is this a known problem with Squid ?? Thanks for ANY help!!
ALberto G.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi !!! sorry for the late response ... I'm installing a Linux and a SQUID to perform a test ... and i'll tell you !!! Byes from Argentina !!
MCP Bruno Capuano Jefe de Desarrollo PECTRA Technology Inc. All the Solutions in One Product +54(351)4245756 - int. 301 www.pectra.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I'm using SQUID and I've exactly the same problem! Without username and password it say Error 407 authentication required With username and password -> Timeout!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Bruno, i'm becoming *crazy* with a probleme. * I have a simple WebService, called "HelloWorld" * i access the web server using a proxy (SQUID on linux). * if my proxy does not require authentication, all works fine! * if my proxy REQUIRE authentication, i cannot reach my service and I have a "Time out" error.
-- CODE -----
[..]
' Set proxy credentials (NOTE: Domain is empty..) Dim cr As New System.Net.NetworkCredential("proxyUser", "proxyPWD", "") Dim pr As System.Net.WebProxy
' NOTE: using GetDefaultProxy or setting manually is the same result.. pr = New WebProxy("10.23.0.66", 3128) 'pr = WebProxy.GetDefaultProxy
pr.Credentials = cr service.Proxy = pr service.timeout = 10000 '10 seconds timeout
result = service.helloWord() ' <------ TIMEOUT ERROR!!
-- END CODE ----
Is this a known problem with Squid ?? Thanks for ANY help!!
ALberto G.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
If the application is going from client to an outside-the-lan server through a proxy, why wouldn't System.Net.WebProxy.GetDefaultProxy() work? The doc's say that that function grabs the proxy info from IE, which would seem to be good enough in most cases. Any thoughts on this? Am I not understanding something? Thanks.
Tom
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
I'm in a LAN which uses Proxy Server, I dump to DOS, and use the wsdl.exe command line tool
/proxy: The url of the proxy server to use for http requests. The default is to use the system proxy setting.
/proxyusername: /proxypassword: /proxydomain: The credentials to use when the connecting to a proxy server that requires authentication. Short forms are '/pu:', '/pp:' and '/pd:'.
Error: "The request failed with HTTP status 407: Proxy Access Denied".
How to add Web Reference when i'm behind a Proxy Server? Thx a lot!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
The Vs.2003 includes a new window ... In this window you can set this values User Domain Password
And then you can use the WebService through the Proxy.
MCP Bruno Capuano Jefe de Desarrollo PECTRA Technology Inc. All the Solutions in One Product +54(351)4245756 - int. 301 www.pectra.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
General News Question Answer Joke Rant Admin
|