NuSOAP WSDL and HTTP Authentication Problems

Posted on 2004-12-01
Last Modified: 2012-08-13
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;

Question by:Squig
    LVL 48

    Expert Comment

    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?

    Author Comment

    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
    LVL 48

    Expert Comment

    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.


    Author Comment

    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.

    Author Comment

    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.

    Accepted Solution

    PAQed with points refunded (500)

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now