NuSOAP WSDL and HTTP Authentication Problems

I'm using NuSOAP 1.81, which I checked to make sure I
have the latest version to avoid bugs. I created a
SOAP server and I'm able to access the services from
both PHP and Java clients except when I place an
.htaccess file on the server to protect the services.
I can access the wsdl file from the broswer but the
clients are having trouble. Presently, if I make the
client like this it works, except it says " wsdl
error: XML error parsing WSDL from on line 76:
not well-formed (invalid token)":

$client = new
// Check for any errors from the remote service
$err = $client->getError();
 if ($err) {
    echo '<p><b>Error: ' . $err . '</b></p>';

But, my java client keep getting a 401 error, about
authentication. I'm using Apache Axis through JBuilder
to develop my java client. However, if I removed the
authentication files (.htaccess/.htpasswd) from the
server my java clietn works fine.

Can anyone who had this problem and worked around it
give me some help. Some services that would be exposed
I have to protect them, another option I have is to
pass a username and password in service request, but I
think it's a bit of overhead and also I need to
protect the wsdl file not just the services exposed.

I would greatly appreciate some help. Below I listed a
simple server that show's how I'm implementing the
SOAP Server.

// server.php
// Insert the NuSOAP code


// Create an instance of the server
$server = new soap_server;

// Initialize WSDL support
$server->configureWSDL('Events', $NAMESPACE);

// Put the WSDL schema types in the namespace with the
tns prefix
$server->wsdl->schemaTargetNamespace = $NAMESPACE;


      $NAMESPACE . '#' . 'getPerson',
      'Returns a pserson by ID'

function getPerson($personId) {
      if($personId==0||$personId=='') {
            return new soap_fault('Client', '', 'Must supply a
person id.');
      else {
            $aPerson = array(
                  return $aPerson;

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you get a 401 error then the authentication is not satisfied (e.g missing basic-auth-informatio). Whats your content of that .htaccess-file? It has nothing to do with PHP. Maybe your java-client is not able to send such basic-auth-paramas as the PHP-client does. Have you also checked the complete output of the xml-file send by the server for PHP-notices /warnings when protecting is on?
SquigAuthor Commented:
it works fine because I try to access through the browser where it prompts for username and password it works. below is the contents of my .htaccess file. I'm also testing on my workstation.

AuthUserFile "D:/Apache/test0.canreig.local/htdocs/ws/.htpasswd"
AuthName "This is a Restricted Area"
AuthType Basic

<Limit GET POST>
require valid-user
Yes the browser typlical implement this feature correct, but maybe the Java-HTTP-Client/Soap is not able to that basic auth correctly.

To track that error down I would use an network-sniffer an check what is send to see where those errors come from when you use basic-aut to protect that files.

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

SquigAuthor Commented:
It seems it might be some limitations in NuSOAP. If I create a soap service without using WSDL HTTP Authentication works fine, but when I use WSDL it has problems. Using a PHP client, I can get it working if I add the username and password to the URL like this "". I'm about to try using PHP HTTP authentication instead of Apache to see if it owuld make a difference. I've looked through a few post and a number of people seemed to had the same problems, but I haven't seen any solutions as yet. Also, I tried it on a different server to make sure it wasn't my server configuration that was causing the problem, and I had the same problem.
SquigAuthor Commented:
Ok, I got the problem solved. So here's the solution to anyone else who might have the same problem. The client should be as follows:

define('username', 'foo');
define('password', 'bar');
// This is location of the remote service
$client = new soapclient('https://' . username . ":" . password . '', true);

I define the username and password as constants, and that's it.
PAQed with points refunded (500)

Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.