所以我现在真的被困住了。我是soap和WSDL的新手。我知道一些Oop Java和一些Oop Php。我试图在Java WSDL API中调用函数。不需要任何参数的方法可以正常工作并返回值。但是,当我试图将params发送到需要params的方法时,它只会抛出异常。我正在使用php> 5.4。这是我第三天试图弄清楚这没有任何运气。 API的提供者在我的协助中没有任何技术人员,而且我对他们系统的无限文档感到困惑。
我需要在过去一周内在系统中获取所有签到人员,基于预选我选择此API端点(BookingAPI)
$allEndpoints = [AccessAPI, AccountReceivableAPI, BookingAPI, ChildCareAPI, CompanyAPI, CrmAPI, ExtractAPI, GiftCardAPI, PersonAPI, PrivilegeAPI, ProductAPI, QuestionnaireAPI, ResourceBookingAPI, SelfServiceAPI, StaffBookingAPI, StaffBookingAPI, SubscriptionAPI, TestAPI]
但是为了简化这个问题,我选择了一个参数较少的函数。
一些代码:
echo "<pre style=\"display:block;word-wrap: break-word;\">";
$client = new SoapClient($wsdl, array(
"login" => $login,
"password" => $password,
"trace" => 1,
"exceptions" => 0)
);
// TRY DIFFERENT OBJECTIFICATIONS HERE; SEE BELOW
print "Client : \n";
var_dump($client);
print "<br>Functions : \n";
// var_dump($client->__getFunctions());
print "<br>Types : \n";
// var_dump($client->__getTypes());
// print "<br />\n Request : ".htmlspecialchars($client->__getLastRequest());
// print "<br />\n Response: ".htmlspecialchars(utf8_decode($client->__getLastResponse()));
print "<br>Values : \n";
print_r($value);
在一些tuts和一些SO线程后,我尝试了以下内容:
当我尝试时:
$myClass->token = new \stdClass;
$myClass->personId = '6204';
$value = $client->getDetails($myClass);
我明白了:
Warning: Creating default object from empty value in /path/to/dist/index.php on line 143 Fatal error: SOAP-ERROR: Encoding: object has no 'center' property in /path/to/dist/index.php on line 145
如果我尝试:
$myParam = new SoapParam("6204", "PersonKey");
$value = $client->getDetails($myParam);
我明白了:
SoapFault Object
(
[message:protected] => dk.procard.eclub.api.v4.exceptions.APIException: dk.procard.eclub.api.exceptions.ImplException: java.lang.IllegalArgumentException: Unknown center
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /path/to/dist/index.php
[line:protected] => 154
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /path/to/dist/index.php
[line] => 154
[function] => __call
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => getDetails
[1] => Array
(
[0] => SoapParam Object
(
[param_name] => PersonKey
[param_data] => 6204
)
)
)
)
[1] => Array
(
[file] => /path/to/dist/index.php
[line] => 154
[function] => getDetails
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => SoapParam Object
(
[param_name] => PersonKey
[param_data] => 6204
)
)
)
)
[previous:Exception:private] =>
[faultstring] => dk.procard.eclub.api.v4.exceptions.APIException: dk.procard.eclub.api.exceptions.ImplException: java.lang.IllegalArgumentException: Unknown center
[faultcode] => env:Server
[detail] => stdClass Object
(
[APIException] => stdClass Object
(
[errorCode] => ILLEGAL_ARGUMENT
[errorMessage] => dk.procard.eclub.api.exceptions.ImplException: java.lang.IllegalArgumentException: Unknown center
[message] => dk.procard.eclub.api.v4.exceptions.APIException: dk.procard.eclub.api.exceptions.ImplException: java.lang.IllegalArgumentException: Unknown center
)
)
)
来自文档:
Person getDetails(PersonKey personId)抛出APIException
Gets the details for a person.
参数:
personId - 必填。应该返回详细信息的人员的身份
返回:
该人的详细信息
抛出:APIException - 只会抛出
一般错误代码。
参见:blabla
如何通过所需的响应进行重新设定?非常感谢所有的帮助和指示,谢谢!
[编辑]
跟进问题:
如何在我的请求中发送&#34; id&#34; -parameter? findPersons(arg0-&gt; attributes-&gt; id);
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v4="path/to/api?wsdl">
<soapenv:Header/>
<soapenv:Body>
<v4:findPersons>
<arg0>
<!--Zero or more repetitions:-->
<attributes>
<!--Optional:-->
<id>?</id>
<!--Optional:-->
<value>?</value>
</attributes>
<!--Optional:-->
<birthday>?</birthday>
<!--Optional:-->
<center>?</center>
<!--Optional:-->
<country>?</country>
<!--Optional:-->
<name>?</name>
<!--Optional:-->
<personType>?</personType>
<!--Optional:-->
<phoneNumber>?</phoneNumber>
<!--Optional:-->
<socialSecurityNumber>?</socialSecurityNumber>
</arg0>
</v4:findPersons>
</soapenv:Body>
</soapenv:Envelope>
答案 0 :(得分:0)
第一种方法:
$myClass = new \stdClass;
$myClass->personId = 6204;
$value = $client->getDetails(array($myParam));
第二种方法:
$myParam = new SoapVar("6204", XSD_STRING); // it should be the same type of personId at wsdl
$value = $client->getDetails(array('personId' => $myParam));