相关疑难解决方法(0)

如何使用SoapClient类进行PHP SOAP调用

我习惯编写PHP代码,但不经常使用面向对象的编码.我现在需要与SOAP(作为客户端)进行交互,并且无法正确获取语法.我有一个WSDL文件,它允许我使用SoapClient类正确设置新连接.但是,我无法实际进行正确的调用并返回数据.我需要发送以下(简化)数据:

  • 联系人ID
  • 联系人姓名
  • 一般说明

WSDL文档中定义了两个函数,但我只需要一个(下面的"FirstFunction").这是我运行的脚本,用于获取有关可用功能和类型的信息:

$client = new SoapClient("http://example.com/webservices?wsdl");
var_dump($client->__getFunctions()); 
var_dump($client->__getTypes()); 
Run Code Online (Sandbox Code Playgroud)

这是它生成的输出:

array(
  [0] => "FirstFunction Function1(FirstFunction $parameters)",
  [1] => "SecondFunction Function2(SecondFunction $parameters)",
);

array(
  [0] => struct Contact {
    id id;
    name name;
  }
  [1] => string "string description"
  [2] => string "int amount"
}
Run Code Online (Sandbox Code Playgroud)

假设我想用数据调用FirstFunction:

  • 联系ID:100
  • 联系人姓名:约翰
  • 概述:油桶
  • 金额:500

什么是正确的语法?我一直在尝试各种各样的选择,但看起来肥皂结构非常灵活,所以有很多方法可以做到这一点.无法从手册中弄清楚......


更新1:试过MMK的样本:

$client = new SoapClient("http://example.com/webservices?wsdl");

$params = array(
  "id" => 100,
  "name" => "John",
  "description" => "Barrel of Oil",
  "amount" => 500,
);
$response = $client->__soapCall("Function1", array($params)); …
Run Code Online (Sandbox Code Playgroud)

php soap

121
推荐指数
5
解决办法
37万
查看次数

内容类型'text/xml; charset = utf-8'不是预期的类型'application/soap + xml; 字符集= UTF-8'

我一直在努力向肥皂服务器发送正确的请求.我一直在收到错误消息.

这是我的xml

得到最后的请求(添加换行符):

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body><ns1:TestData1><ns1:iVal>1</ns1:iVal></ns1:TestData1></SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)

得到最后的回应:

请求标题:

POST /DPWebService/CardsService.svc/ICardsService HTTP/1.1
Host: d67v7tg1
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.2.9-1
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tempuri.org/ICardsService/TestData1"
Content-Length: 254
Run Code Online (Sandbox Code Playgroud)

这是回复.

object(SoapFault)#2 (8) { 
["message:protected"]=> string(142) "Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'." 
["string:private"]=> string(0) "" 
["code:protected"]=> int(0) 
["file:protected"]=> string(32) "C:\localhost\www\test5\index.php" 
["line:protected"]=> int(208) 
["trace:private"]=> array(3) { 
    [0]=> array(4) { 
        ["function"]=> string(11) "__doRequest" 
        ["class"]=> string(10) "SoapClient" 
        ["type"]=> string(2) "->" 
        ["args"]=> array(5) { …
Run Code Online (Sandbox Code Playgroud)

php soap

6
推荐指数
2
解决办法
3万
查看次数

NuSOAP:如何更改内容类型的请求?

在使用.NET WCF Web服务时,我得到以下响应(错误):

不支持的HTTP响应状态415无法处理消息,因为内容类型为'text/xml; charset = UTF-8'不是预期的类型'application/soap + xml; 字符集= UTF-8' .

如何更改内容类型?我在NuSOAP论坛/文档中找不到它,或者我可能会忽略某些东西....

php web-services content-type nusoap

4
推荐指数
1
解决办法
4万
查看次数

使用PHP为特定服务调用SOAP方法

很抱歉必须这样做,但是我没有得到运行这个特定网络服务的人的爱.我以前从未使用过SOAP.

这是我试图打电话的方法

这是我认为应该工作的代码

    public function soapTest(){

            echo "start <br />";
            use_soap_error_handler(true);
            $client = new SoapClient("https://cwi.rezexchange.com:9991/?wsdl");

                // here's the problem. What goes in the parenthesis?
            $result = $client->CwiRateDetails(????);

            echo($result);
            echo "<br /> end";

        }
Run Code Online (Sandbox Code Playgroud)

现在我猜这会告诉我括号应该包含什么.

POST /Service.asmx HTTP/1.1
Host: cwi.rezexchange.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://hotelconcepts.com/CwiRateDetails"

<?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>
    <CwiRateDetails xmlns="http://hotelconcepts.com/">
      <PropertyCode>string</PropertyCode>
      <DateFrom>dateTime</DateFrom>
      <DateTo>dateTime</DateTo>
      <RatePlan>string</RatePlan>
      <RoomType>string</RoomType>
      <PromotionalRates>boolean</PromotionalRates>
    </CwiRateDetails>
  </soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)

我猜是有点像

$result = $client->CwiRateDetails($PCode, $DateFrom, $DateTo, $RatePlan, $RoomType, false);
Run Code Online (Sandbox Code Playgroud)

应该管用.但我不知道日期格式是什么,或者房间类型是什么或如何引用费率计划.

现在.在我通过电子邮件与他们一起去猿人之前,我错误地认为他们需要提供更多信息吗?或者是否有某种SOAP技巧可以用来从某个地方获取信息?

php soap

2
推荐指数
1
解决办法
4841
查看次数

标签 统计

php ×4

soap ×3

content-type ×1

nusoap ×1

web-services ×1