p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   .NET Web Services (http://p2p.wrox.com/forumdisplay.php?f=102)
-   -   Accessing a WS in a password protected directory (http://p2p.wrox.com/showthread.php?t=14190)

FleaBite June 14th, 2004 12:48 PM

Accessing a WS in a password protected directory

I have developed a web service in PHP using NuSOAP. I want some form of security for this WS, so I've put it in a directory which is password protected, using an htaccess file. The authentication type is Basic.

Now I'm developing a client app, written in C#, to consume this web service, but I'm having a bit of trouble to get access. I've done something similar to the example I found at MSDN (http://msdn.microsoft.com/library/de...ebservices.asp) to send the necessary credentials to the webserver:


// Create a new instance of the proxy class to an XML
// Web service method.
MyMath.Math math = new MyMath.Math();

// Create a new instance of CredentialCache.
CredentialCache credentialCache = new CredentialCache();

// Create a new instance of NetworkCredential using the client
// credentials.
NetworkCredential credentials = new NetworkCredential(UserName,SecurelyStroredPassword,Domain);

// Add the NetworkCredential to the CredentialCache.
credentialCache.Add(new Uri(math.Url), "Basic", credentials);

// Add the CredentialCache to the proxy class credentials.
math.Credentials = credentialCache;

// Call the method on the proxy class.
int result = math.Add(3,5);

but I keep getting an "HTTP 400: Bad Request" response. I know that there must be something going wrong while sending the credentials, because when I call the web service when the password protection is off, I get the desired result.

What can I do to solve this? And is it even possible to access a directory which is protected by an htaccess file? Or can I only use this method when the webserver is running IIS?

FleaBite July 4th, 2004 02:30 PM

Still looking for the answer. Anyone?

Hal Levy July 6th, 2004 08:47 AM

IIS doesn't use .htaccess files

Bad Request isn't unauthorized.. it means the request is bad.. meaning something in your request is likely malformed. Are you sure your makeing the credential call correctly? I don't know why the credentials wouldn't work- but they might not with a different webserver... I would use a sniffer to look at the packets going over the wire and see if I could figure out what was going on.

Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee

FleaBite July 6th, 2004 09:44 AM

Heh, I've had this problem for a couple of weeks. But only half an hour after I kicked this topic back up, I found the solution [8)]. I have to send the request through a proxy server for it to work

All times are GMT -4. The time now is 02:12 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.