通过 SOAP 从 PHP 调用 Moodle 函数

发布于 2024-10-31 00:16:54 字数 1043 浏览 6 评论 0原文

我在开始通过提供的 SOAP Web 服务将 PHP 脚本连接到 Moodle 2.0 时遇到困难。由于对 SOAP 了解不多,我想我只需连接并从那里开始。但是,我什至无法连接......

$soap=new SoapClient(
    'http://mymoodleserver/webservice/xmlrpc/server.php?wstoken=asdfasdfasdfasdfasdf',
    array(
        'trace'=>1,
        'exceptions'=>true,
        'cache_wsdl'=>WSDL_CACHE_NONE
    )
);

这返回:

致命错误:未捕获 SoapFault 异常:[WSDL] SOAP-ERROR:正在解析 WSDL:无法加载...

如果我直接访问此 URL,则不会返回任何数据。用 Fiddler 查看它表明服务器确实返回了 0 的内容长度。

我找不到任何关于此的文档...有 其他协议的文档

我假设 SoapClient 期望一些 WSDL 来定义哪些函数可用的。我有这些函数和参数的列表(不感谢官方文档页面 )。我如何指示 SoapClient 不用担心 WSDL 并继续?

我检查了 Moodle 服务器上 PHP 错误日志中的错误,结果显示是干净的。

I am having difficulty getting started with interfacing my PHP script to Moodle 2.0 over the SOAP Web Service provided. Not knowing much about SOAP, I figured I would simply connect and go from there. However, I can't even get connected...

$soap=new SoapClient(
    'http://mymoodleserver/webservice/xmlrpc/server.php?wstoken=asdfasdfasdfasdfasdf',
    array(
        'trace'=>1,
        'exceptions'=>true,
        'cache_wsdl'=>WSDL_CACHE_NONE
    )
);

This returns:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load...

If I were to go to this URL directly, no data is returned. Looking at it with Fiddler shows that the server does indeed return a Content-Length of 0.

There isn't any documentation on this that I could find... there is documentation for other protocols however.

I am assuming that the SoapClient is expecting some WSDL to define what functions are available. I have a list of those functions and parameters (no thanks to the official documentation page). How can I instruct SoapClient to not worry about the WSDL and carry on?

I have checked for errors in the PHP error log on the Moodle server, and it turned up clean.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妄断弥空 2024-11-07 00:16:54

使用非wsdl模式的方法是将其添加到uri

$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
                                     'uri'      => "http://test-uri/"));

ofocurse中,使用trace然后查找getlastrequest和getlastresponse

$result = $client->SomeFunction();
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";

http://www.php.net/manual/en/soapclient.getlastrequest.php

使用 xmlspy 方便调试。

The way to use the non wsdl mode is to add it to the uri

$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
                                     'uri'      => "http://test-uri/"));

Ofocurse, use trace and then look for getlastrequest and getlastresponse

$result = $client->SomeFunction();
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";

http://www.php.net/manual/en/soapclient.getlastrequest.php

Use xmlspy for easy debugging.

沫尐诺 2024-11-07 00:16:54

关键在于错误,因此我开始查看 Moodle 文档,了解会发生什么,而不是 WSDL。

检查 SoapClientMoodle 文档,您可以看到 Moodle 不提供 WSDL 因此您需要在 中使用 SoapClient非 WSDL 模式

The key is in the error, so I started looking at the documentation for Moodle knowing what to expect, no WSDL.

Check the documentation for SoapClient and the documentation for Moodle as you can see Moodle doesnt offer WSDL so you need to use the SoapClient in non-WSDL mode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文