简体   繁体   中英

SoapServer() call not able to access wsdl file

I have a symfony based product in which i have to expose a Soap API. I have created the wsdl file which is accessible from browser after entering Username and Pasword for basic http auth check.

When i am using SoapClient to call that API and providing Username and Password through header it is able to access WSDL and making call to SoapServer Endpoint. But when the SoapServer() calls for that wsdl link, its showing error.

SoapClient():

$client = new \SoapClient('http://example.com/soaptest?wsdl', array(
        "exceptions" => 0,
        "trace" => 1,
        'stream_context' => stream_context_create(array(
            'http' => array(
                'header' => "Authorization: Basic " . base64_encode("$username:$password")
            ),
        )),
    ));

SoapServer():

ini_set("soap.wsdl_cache_enabled", "0");

$server = new SoapServer($wsdl);    //Here SoapServer not able to access WSDl because of .htaccess

$server->setObject($this->get($class));
ob_start();
$server->handle();
$result = ob_get_clean();

return $result;

I also have a .htaccess as :

DirectoryIndex app.php



<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On


    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]


    RewriteCond %{HTTP:Authorization} .
    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]


    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]


    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]


    RewriteRule ^ %{ENV:BASE}/app.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>

        RedirectMatch 302 ^/$ /app.php/# RedirectTemp cannot be used instead
    </IfModule>
</IfModule>
php_value date.timezone UTC

AuthType Basic
AuthName "Login"
AuthUserFile /etc/apache2/config/.htpasswd

Require expr %{REQUEST_URI} !~ m#^/(admin|login|soaptest)#
Require valid-user
#<RequireAll>
 # Require ip 127.0.0.1
#</RequireAll>

So here the control goes to the SoapServer() call, but while trying to access wsdl in SoapServer() it is showing:-

Error {"500":"Error: SOAP-ERROR: Parsing WSDL: Couldn't load from ' http://example.com/soaptest?wsdl ' : failed to load external entity " http://example.com/soaptest?wsdl ""}

So is there a way to provide Basic Auth Username and Password in SoapServer call? Because i am thinking that SoapServer while looking for WSDl file is not able to access that link. Also all the file are in same server. And no external call is made .

I have also tried from SoapUI and same error occured.

The last 3 line in .htaccess helps solve the issue somewhat but is there any better way to resolve this issue?

.htaccess is necessary for my project so it cannot be removed.

Are you sure a SoapServer is able to use an URL as a WSDL file ? It should be a local file, not a distant one. If it works, it is probably because PHP can load URL ressource like if they are on the local machine using the fopen wrapper. See examples here : http://php.net/manual/en/soapserver.soapserver.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM