0

如果我使用 SoapUi 测试服务,则操作失败,但如果使用 PHP 实现 Soap 客户端,则参数始终为空,并且我得到 NullReferenceException。

<?php
$options = array();
$options['classmap']['Abonnent']  = 'RequestType';

$client = new SoapClient('wsdllink',$options);

 class RequestType
{
   public $Email;
   public $Nachname;
   public $Passwort;
   public $Vorname;
}

$abo         = new RequestType;
$abo->Email    = 'email';
$abo->Nachname    = 'lastname';
$abo->Passwort    = 'passwort';
$abo->Vorname    = 'firstname';
try {
    $result = $client->Abonnieren($abo);
} catch(SoapFault $e) {
    echo "Request :\n". ($client->__getLastRequest()). "\n";
    echo "Response :\n". ($client->__getLastResponseHeaders()). "\n";
    echo "Response :\n". ($client->__getLastResponse()). "\n";
    echo($e->getMessage());
} catch(Exception $e) {
    echo $e->getMessage();
}

?>

var_dump($client->__getFunctions())

 array(2) {
  [0]=>
  string(53) "AbonnierenResponse Abonnieren(Abonnieren $parameters)"
  [1]=>
  string(53) "RegisterIBResponse RegisterIB(RegisterIB $parameters)"
}

var_dump($client->__getTypes())

 array(8) {
  [0]=>
  string(87) "struct Abonnent {
 string Email;
 string Nachname;
 string Passwort;
 string Vorname;
}"
  [1]=>
  string(41) "struct Abonnieren {
 Abonnent abonnent;
}"
  [2]=>
  string(56) "struct AbonnierenResponse {
 boolean AbonnierenResult;
}"
  [3]=>
  string(41) "struct RegisterIB {
 Abonnent abonnent;
}"
  [4]=>
  string(56) "struct RegisterIBResponse {
 boolean RegisterIBResult;
}"
  [5]=>
  string(8) "int char"
  [6]=>
  string(17) "duration duration"
  [7]=>
  string(11) "string guid"
}

来自 SoupUI 的 XML

<soapenv:Envelope
 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:tem="http://tempuri.org/"
  xmlns:prm="http://schemas.datacontract.org/2004/07/PRMarketService">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:Abonnieren>
         <tem:abonnent>
            <prm:Email>email</prm:Email>
            <prm:Nachname>lastname</prm:Nachname>
            <prm:Passwort>passwort</prm:Passwort>
            <prm:Vorname>firstname</prm:Vorname>
         </tem:abonnent>
      </tem:Abonnieren>
   </soapenv:Body>
</soapenv:Envelope>

来自 PHP 客户端的 XML

 <?xml version="1.0" encoding="UTF-8"?>
   <SOAP-ENV:Envelope
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:ns1="http://schemas.datacontract.org/2004/07/PRMarketService"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:ns2="http://tempuri.org/">
            <SOAP-ENV:Body>
                <ns2:Abonnieren xsi:type="ns1:Abonnent">
                    <ns1:Email>email</ns1:Email>
                    <ns1:Nachname>lastname</ns1:Nachname>
                    <ns1:Passwort>passwort</ns1:Passwort>
                    <ns1:Vorname>firstname </ns1:Vorname>
                </ns2:Abonnieren>
            </SOAP-ENV:Body>
        </SOAP-ENV:Envelope>
4

1 回答 1

0

比较 SoapUI 和 PHP 的 SoapClient 发送的消息,例如使用Fiddler。如果我没记错的话,您必须将 PHP 发送的 XML 主体包装在一个以相应 SOAPAction 命名的根元素中。

像这样的东西:

class AbonnierenRequest
{
    public $Abbonent;   
}

class Abonnent
{
    public $Email;
    public $Nachname;
    public $Passwort;
    public $Vorname;
}

$request = new AbonnierenRequest();
$request->Abonnent = new Abonnent();

$request->Abonnent->Email = 'email';
$request->Abonnent->Nachname = 'lastname';
$request->Abonnent->Passwort = 'passwort';
$request->Abonnent->Vorname = 'firstname';

$result = $client->Abonnieren($request);
于 2013-10-01T09:10:16.580 回答