![](/img/trans.png)
[英]How programmatically (!) validate soap request/response with wsdl?
[英]How to do a wsdl Request-response with soap in php?
所以我现在真的很困。 我是肥皂和WSDL的新手。 我知道一些Oop Java和一些Oop Php。 我试图在Java WSDL API中调用函数。 不需要任何参数的方法可以正常工作并返回值。 但是,当我尝试将参数发送到需要参数的方法时,它只会引发异常。 我正在使用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);
经过一些练习和一些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-必填。 应返回其详细信息的人员的ID
返回:
这个人的细节
抛出:APIException-仅抛出
一般错误代码。
另请参阅:blabla
如何进行具有所需响应的重新设置? 非常感谢所有帮助和指示,谢谢!
[编辑]
后续问题:
如何在请求中发送“ id”参数? findPersons(arg0-> attributes-> 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>
对于您的第一种方法:
$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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.