非 WSDL 模式下的 SOAP 问题 [英] Issues with SOAP in non-WSDL mode

查看:35
本文介绍了非 WSDL 模式下的 SOAP 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个简单的网络服务,用于在我拥有的两个网站之间进行通信.

I am making a simple web service for communication between two sites I own.

因为它只是一个基本的应用程序,我一直在没有 WSDL 文件的情况下工作,所以在 non-WSDL 模式,正如 PHP 手册所称的那样.

Since it is only a basic application, I've been working without a WSDL file, so in non-WSDL mode as the PHP manual calls it.

这基本上是客户端的样子:

This is basically what the client-side looks like:

$client = new SoapClient(null, array('location' => $location, 'uri' => '', 'trace' => TRUE));

$res = $client->__soapCall('myFunc', array($param));

在服务器端,我有一个名为 myFunc 的函数:

On the server-side, I have a function called myFunc:

$soap = new SoapServer(null, array('uri' => ''));

$soap->addFunction('myFunc');

//Use the request to invoke the service
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $soap->handle();
}

当我实际尝试调用 myFunc 函数时,出现错误:

When I actually try invoking the myFunc function, I get and error:

Function 'ns1:myFunc' doesn't exist

出于某种原因,soap 服务器在函数名称前添加了 ns1:

For some reason, the soap server is prepending ns1: to the function name!

使用 $client->__getLastRequest(),我得到:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
    <ns1:getTopElement>
        <param0 xsi:type="xsd:string">rightcolBox</param0>
    </ns1:getTopElement>
</SOAP-ENV:Body>

我不是 SOAP 专家,但在我看来是客户端在发出请求时导致错误 - 还是服务器误解了它?

I'm not a SOAP expert, but it seems to me that the client is causing the error in making the request - or is the server misinterpreting it?

我该如何解决这个问题?

How can I fix this issue?

推荐答案

我遇到了同样的问题.当我将 SoapClient 选项的 uri 设置为非空时,问题就解决了.

I had the same problem. When I set SoapClient options' uri to not null, the problem was solved.

$client = new SoapClient(null, array('location' => $location, 'uri' => 'foo', 'trace' => TRUE));

是的,它可以是任何字符串,甚至是本例中的foo".

Yes, it can be any string, even "foo" as in this example.

这篇关于非 WSDL 模式下的 SOAP 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆