Click here to Skip to main content
12,887,933 members (47,519 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET WebService

My system has to consume a web service on my client's server to retrieve XML data. The web service is secured by IP address so that it only returns the right result only when the consumer is from a known IP Address. I'm still developing my system, and for me to test the system, my client has my public IP address (range of IP address so that other developers can test as well) to add it to their IP address list. I can access to the web service directly from my browser. However, I'm not able to access to the web service from my code. (They redirect me to their login page right now instead of sending me XML data.) My understanding of IP address of my development (local) environment is that my system uses local host but when it reaches to the web service the web service sees my request as from my public IP address. (like localhost -> private ip address -> public ip address) Is that right? In that case, is there anything I should do in my code? Or am I thinking totally wrong?

Thank you in advance.
Posted 14-Feb-13 9:06am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you are being redirected to a login page, that would indicate that you need authentication to access the web service.
When you connect using your browser you are allowed through because it it passing your credentials through automatically for authentication.
When you connect using your web server code, your web server will send it as an anonymous request by default. You will need to set proper credentials on the request in your code before you send it in order not to get punted to the login.
Espen Harlinn 15-Feb-13 9:51am
Marcus Kramer 15-Feb-13 9:56am
Thanks, Espen.
Meg Takahashi 15-Feb-13 9:57am
Hi Marcus,
Thanks for your response. I did the followings and I still get the same result. Am I doing wrong?

objRequest.PreAuthenticate = True
objRequest.Credentials = CredentialCache.DefaultNetworkCredentials

objRequest.Credentials = New System.Net.NetworkCredential("myUserName", "myPassword", "myNetworkDomainName")

I am using GET method, but does that change anything in this situation?
Marcus Kramer 15-Feb-13 10:07am
If the web service requires SOAP headers, you may want to examine this: How to: Perform Custom Authentication Using SOAP Headers
I haven't done this in a while now, so I'm a little rusty on the details.(and I'm supposed to be getting some work done...) If I get a chance I'll take a peek at some of my code where I've done this and get back to you, but it may not be for a while.
Meg Takahashi 15-Feb-13 10:10am
Thank you Marcus! I'm gonna read the article to see if that is what I need. Thank you for your help!
Marcus Kramer 15-Feb-13 10:46am
You are very welcome.
Meg Takahashi 22-Feb-13 10:49am
Hi, the authentication was right to solve this problem, but I needed to add the info to the request header directly. This is my code which fixed the issue.

Dim strAuth As String = "Digest " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(strUserAndDomain + ":" + strPassword))
objRequest.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequested
objRequest.Headers.Add("Authorization", strAuth)

Thank you everyone!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170424.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100