简体   繁体   English

SoapServer()调用无法访问wsdl文件

[英]SoapServer() call not able to access wsdl file

I have a symfony based product in which i have to expose a Soap API. 我有一个基于symfony的产品,我必须在其中公开Soap API。 I have created the wsdl file which is accessible from browser after entering Username and Pasword for basic http auth check. 我创建了wsdl文件,在输入用户名和密码后可以从浏览器访问以进行基本的http身份验证。

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. 当我使用SoapClient调用该API并通过头提供用户名和密码时,它能够访问WSDL并调用SoapServer Endpoint。 But when the SoapServer() calls for that wsdl link, its showing error. 但是当SoapServer()调用该wsdl链接时,它显示错误。

SoapClient(): 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(): 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 : 我也有一个.htaccess:

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:- 所以这里控件转到SoapServer()调用,但是在尝试访问SoapServer()中的wsdl时它显示: -

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 ""} 错误{“500”:“错误:SOAP-ERROR:解析WSDL:无法从' http://example.com/soaptest?wsdl '加载:无法加载外部实体” http://example.com/soaptest ?wsdl “”}

So is there a way to provide Basic Auth Username and Password in SoapServer call? 那么有没有办法在SoapServer调用中提供Basic Auth用户名和密码? Because i am thinking that SoapServer while looking for WSDl file is not able to access that link. 因为我认为SoapServer在查找WSDl文件时无法访问该链接。 Also all the file are in same server. 此外,所有文件都在同一台服务器上。 And no external call is made . 并且没有外部呼叫

I have also tried from SoapUI and same error occured. 我也试过SoapUI并发生了同样的错误。

The last 3 line in .htaccess helps solve the issue somewhat but is there any better way to resolve this issue? .htaccess中的最后3行有助于解决这个问题,但有没有更好的方法来解决这个问题?

.htaccess is necessary for my project so it cannot be removed. .htaccess是我的项目所必需的,因此无法删除。

Are you sure a SoapServer is able to use an URL as a WSDL file ? 您确定SoapServer能够将URL用作WSDL文件吗? 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. 如果它工作,可能是因为PHP可以加载URL ressource,就像它们使用fopen包装器在本地机器上一样。 See examples here : http://php.net/manual/en/soapserver.soapserver.php 请参阅此处的示例: http//php.net/manual/en/soapserver.soapserver.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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