Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从PHP或ajax使用wsdl SOAP web服务_Php_Ajax_Web Services_Soap - Fatal编程技术网

如何从PHP或ajax使用wsdl SOAP web服务

如何从PHP或ajax使用wsdl SOAP web服务,php,ajax,web-services,soap,Php,Ajax,Web Services,Soap,我试图使用PHP或AJAX提供的SOAP web服务,但我的ws-provider允许我的VPS IP,因此web服务可以从中工作,但我需要使用网页上的数据(在我的VPS中运行),因此我尝试使用以下PHP: <?php $wsdl = "https://an.url?wsdl"; $options = array( 'Usuario' => "anUser", 'Clave' => "aPassword", 'Rut' => "someDat

我试图使用PHP或AJAX提供的SOAP web服务,但我的ws-provider允许我的VPS IP,因此web服务可以从中工作,但我需要使用网页上的数据(在我的VPS中运行),因此我尝试使用以下PHP:

<?php
$wsdl = "https://an.url?wsdl";
$options = array(
     'Usuario' => "anUser",
     'Clave' => "aPassword",
     'Rut' => "someData",
     'Dv' => "someMoreData"
);
libxml_disable_entity_loader(false);
$client = new SoapClient($wsdl, $options);
echo '<pre>'.print_r($client,true).'</pre>';
?>

但它抛出了一个错误:

问题是我正在尝试访问名为“obtenerReporteFinal”的方法,我不知道在哪里指定它,可能这是第一个错误

因此,我搜索了另一种使用soapweb服务的方法,并找到了使用ajax的post。因为我的VPS上有一个PHP+JavaScript网页,所以我尝试了以下方法:


$(文档).ready(函数(){
jQuery.support.cors=true;
$(document).on(“click”、“#btnQlo”,function(){CallService()});
});
函数CallService()
{
var-webServiceURL=https://an.url?wsdl';
var soapMessage='';
soapMessage+='';
soapMessage+=''
soapMessage+=''
soapMessage+=''
soapMessage+=''被阻止,我的web服务提供商如何允许我使用它

那么,我怎样才能在上述任何一种情况下做到这一点呢?我真的很困惑,因为这是我第一次使用soapweb服务


编辑:我应该在VPS中实现SSL吗?

您使用的URL似乎无效/不正确。错误表明客户端无法连接。一旦您使用正确的URL,请连接,然后向您创建的客户端对象发送请求(
$client
,在您的示例中)。您提到了
obtenerReporteFinal
,所以它应该是
$client->obtenerReporteFinal()
,包含函数在
()
@Dave中作为数组所需的任何参数。感谢您对该方法的说明。URL在SoapUI工具中工作,所以我认为它是正确的。定义“工作”。我应该能够“点击”它使用浏览器访问,但失败了,这就是为什么我对它的评论无效。@Dave如果您使用相同的URL和“”中的数据“Usuario”、“Clave”、“Rut”、“Dv”从SoapUI尝试,它将返回响应。
<!DOCTYPE html>
<html>
<head>
</head>
<body>


<input type="button" id="btnQlo" value="Call Web Service" />


<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    jQuery.support.cors = true;
    $(document).on("click","#btnQlo",function(){CallService()});
});


function CallService()
{
    var webServiceURL = 'https://an.url?wsdl';
    var soapMessage = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://another.url/">';
    soapMessage+='<soapenv:Header/>';
        soapMessage+='<soapenv:Body>'
            soapMessage+='<com:obtenerReporteFinal>'
                soapMessage+='<!--Optional:-->'
                    soapMessage+='<arg0>'
                    soapMessage+='<Usuario>anUser</Usuario>'
                    soapMessage+='<Clave>aPassword</Clave>'
                    soapMessage+='<Rut>someData</Rut>'
                    soapMessage+='<Dv>someMoreData</Dv>'
                soapMessage+='</arg0>'
            soapMessage+='</com:obtenerReporteFinal>'
        soapMessage+='</soapenv:Body>'
    soapMessage+='</soapenv:Envelope>';

    $.ajax({
        url: webServiceURL, 
        type: "POST",
        crossDomain : true,
        dataType: "xml", 
        data: soapMessage,
        processData: false,
        contentType: "text/xml; charset=\"utf-8\"",
        success: function(data){
            console.log(data);
        }
    });
}
</script>

</body>
</html>