Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 253523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:46:08+00:00 2026-05-11T21:46:08+00:00

I am trying to connect to a Web Service which is password protected and

  • 0

I am trying to connect to a Web Service which is password protected and the url is https. I can’t figure out how to authenticate before the script makes a request. It seems like it makes a request as soon as I define the service. For instance, if I put in:

$client = new SoapClient("https://example.com/WSDL/nameofservice",
       array('trace' => 1,)
);

and then go to the site on the browser, I get:

Fatal error: Uncaught SoapFault exception: 
[WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from
'https://example.com/WSDL/nameofservice' in /path/to/my/script/myscript.php:2 
Stack trace: #0 /path/to/my/script/myscript.php(2): 
SoapClient->SoapClient('https://example...', Array) #1 {main} thrown in 
/path/to/my/script/myscript.php on line 2

If I try defining the service as a Soap Server, like:

$server= new SoapServer("https://example.com/WSDL/nameofservice");

I get:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>WSDL</faultcode>
<faultstring>
SOAP-ERROR: Parsing WSDL: 
Couldn't load from 'https://example.com/WSDL/nameofservice'
</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I haven’t tried sending a raw request envelope yet to see what the server returns, but that may be a workaround. But I was hoping someone could tell me how I can set it up using the php built-in classes. I tried adding “userName” and “password” to the array, but that was no good. The problem is that I can’t even tell if I’m reaching the remote site at all, let alone whether it is refusing the request.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:46:08+00:00Added an answer on May 11, 2026 at 9:46 pm

    The problem seems to be that the WSDL document is somehow protected (basic authentication – I don’t thinkg that digest authentication is supported with SoapClient, so you’d be out of luck in this case) and that the SoapClient therefore cannot read and parse the service description.

    First of all you should try to open the WSDL location in your browser to check if you’re presented an authentication dialog. If there is an authentication dialog you must make sure that the SoapClient uses the required login credentials on retrieving the WSDL document. The problem is that SoapClient will only send the credentials given with the login and password options (as well as the local_cert option when using certificate authentication) on creating the client when invoking the service, not when fetching the WSDL (see here). There are two methods to overcome this problem:

    1. Add the login credentials to the WSDL url on the SoapClient constructor call

       $client = new SoapClient(
           'https://' . urlencode($login) . ':' . urlencode($password) . '@example.com/WSDL/nameofservice',
           array(
               'login' => $login,
               'password' => $password
           )
       );
      

    This should be the most simple solution – but in PHP Bug #27777 it is written that this won’t work either (I haven’t tried that).

    1. Fetch the WSDL manually using the HTTP stream wrapper or ext/curl or manually through your browser or via wgetfor example, store it on disk and instantiate the SoapClient with a reference to the local WSDL.

    This solution can be problematic if the WSDL document changes as you have to detect the change and store the new version on disk.

    If no authentication dialog is shown and if you can read the WSDL in your browser, you should provide some more details to check for other possible errors/problems.

    This problem is definitively not related to the service itself as SoapClient chokes already on reading the service descripion document before issuing a call to the service itself.

    EDIT:

    Having the WSDL file locally is a first step – this will allow the SoapClient to know how to communicate with the service. It doesn’t matter if the WSDL is directly served from the service location, from another server or is read from a local file – service urls are coded within the WSDL so SoapClient always knows where to look for the service endpoint.

    The second problem now is that SoapClient has no support for the WS-Security specifications natively, which means you must extend SoapClient to handle the specific headers. An extension point to add the required behaviour would be SoapClient::__doRequest() which pre-processes the XML payload before sending it to the service endpoint. But I think that implementing the WS-Security solution yourself will require a decent knowledge of the specific WS-Security specifications. Perhaps WS-Security headers can also be created and packed into the XML request by using SoapClient::__setSoapHeaders() and the appropriate SoapHeaders but I doubt that this will work, leaving the custom SoapClient extension as the lone possibility.

    A simple SoapClient extension would be

    class My_SoapClient extends SoapClient
    {
        protected function __doRequest($request, $location, $action, $version) 
        {
            /*
             * $request is a XML string representation of the SOAP request
             * that can e.g. be loaded into a DomDocument to make it modifiable.
             */
            $domRequest = new DOMDocument();
            $domRequest->loadXML($request);
    
            // modify XML using the DOM API, e.g. get the <s:Header>-tag 
            // and add your custom headers
            $xp = new DOMXPath($domRequest);
            $xp->registerNamespace('s', 'http://www.w3.org/2003/05/soap-envelope');
            // fails if no <s:Header> is found - error checking needed
            $header = $xp->query('/s:Envelope/s:Header')->item(0);
    
            // now add your custom header
            $usernameToken = $domRequest->createElementNS('http://schemas.xmlsoap.org/ws/2002/07/secext', 'wsse:UsernameToken');
            $username = $domRequest->createElementNS('http://schemas.xmlsoap.org/ws/2002/07/secext', 'wsse:Username', 'userid');
            $password = $domRequest->createElementNS('http://schemas.xmlsoap.org/ws/2002/07/secext', 'wsse:Password', 'password');
            $usernameToken->appendChild($username);
            $usernameToken->appendChild($password);
            $header->appendChild($usernameToken);
    
            $request = $domRequest->saveXML();
            return parent::__doRequest($request, $location, $action, $version);
        }
    }
    

    For a basic WS-Security authentication you would have to add the following to the SOAP-header:

    <wsse:UsernameToken>
        <wsse:Username>userid</wsse:Username>
        <wsse:Password>password</wsse:Password>                                 
    </wsse:UsernameToken>
    

    But as I said above: I think that much more knowledge about the WS-Security specification and the given service architecture is needed to get this working.

    If you need an enterprise grade solution for the whole WS-* specification range and if you can install PHP modules you should have a look at the WSO2 Web Services Framework for PHP (WSO2 WSF/PHP)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Visual Studio 2010, I am trying to connect to a web service I
I am trying to connect my App to a Web Service that I created
I'm currently trying to implement a Java client to an SPNEGO protected web service
When trying to connect to a web service using the following $client = new
I am trying to connect to a web service using WS-Security UsernameToken spec 1.0,
I'm trying to figure out which credentials I should be storing to enable use
I'm trying to connect to a web service using IO::Socket::INET (yes, I know that
The author of a web-service that I am trying to connect to, tells me
I am trying to connect to a remote web service endpoint by soap ui
I am trying to connect to ldap with a php web application. If the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.