PHP SOAP 客户端发送 XML

发布于 2025-01-08 15:02:01 字数 913 浏览 0 评论 0原文

我正在尝试使用 PHP 创建一个 Web 服务。以下是我的代码 -

Web 服务器 -

require 'inventory_functions.php';

ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("inventory.wsdl");
$server->addFunction("getItemCount");
$server->handle();

Inventory_functions.php -

function getItemCount($upc){
    //in reality, this data would be coming from a database
    $items = array('12345'=>5,'19283'=>100,'23489'=>'234');
    return $items[$upc];
}

我的客户端测试 -

ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$client = new SoapClient("http://www.xxx.co.uk/service/inventory.wsdl");
$return = $client->getItemName('12345');
print_r($return);

当我运行此代码时,一切正常。数字“5”将在我的浏览器中输出。我真正需要的是如何通过 XML 将数据发送到 SOAP 服务器的一些帮助,我将把这些数据添加到 MySQL。

我如何通过客户端测试发送 XML?

谢谢

I am trying to create a web service with PHP. The following is my code -

Web Server -

require 'inventory_functions.php';

ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("inventory.wsdl");
$server->addFunction("getItemCount");
$server->handle();

Inventory_functions.php -

function getItemCount($upc){
    //in reality, this data would be coming from a database
    $items = array('12345'=>5,'19283'=>100,'23489'=>'234');
    return $items[$upc];
}

My Client Test -

ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$client = new SoapClient("http://www.xxx.co.uk/service/inventory.wsdl");
$return = $client->getItemName('12345');
print_r($return);

When I run this everythign is OK. the number "5" will output in my browser. WhatI really need is some help in how to go about sending data via XML to the SOAP server, from their I will add this data to MySQL.

How would I send the XML vie the client test?

Thanks

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

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

发布评论

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

评论(1

最单纯的乌龟 2025-01-15 15:02:01

我不确定我是否理解你的问题。您想知道应该为 Web 服务提供什么 XML 输入才能发送值“5”?

为了做到这一点,您应该首先分析生成的 wsdl 文件,然后,根据您为客户端选择的编程语言,您可以生成一个客户端存根来与 Web 服务本身交互。

或者,您可以直接向 Web 服务发出带有 XML 的 HTTP POST(应如下所示):

POST /service/mywebservice.php HTTP/1.1
Host: www.xxx.co.uk
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "<your.webservice.namespace>/getItemCount"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <getItemCount xmlns="<your.webservice.namespace>">
      <value>5</value>
    </getItemCount>
  </soap:Body>
</soap:Envelope>

I'm not sure I understand your question. You want to know what XML input you should give your web-service in order to send for instance the value "5"?

In order to do that you should first analyse the wsdl file that is generated, then, depending on your programming language of choice for the client, you may generate a client Stub to interact with the Web-Service itself.

Alternatively, you may issue an HTTP POST with the XML directly to the web-service (should look something like this):

POST /service/mywebservice.php HTTP/1.1
Host: www.xxx.co.uk
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "<your.webservice.namespace>/getItemCount"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <getItemCount xmlns="<your.webservice.namespace>">
      <value>5</value>
    </getItemCount>
  </soap:Body>
</soap:Envelope>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文