SOAP客户端和Windows服务之间的SOAP通信导致NullReferenceException

时间:2013-10-01 09:07:24

标签: c# php .net soap

如果我使用SoapUi测试服务,那么操作会发生,但是如果使用PHP实现Soap客户端,那么参数总是为emty而且我得到一个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($客户端 - &GT; __ getFunctions())

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

的var_dump($客户端 - &GT; __ 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>

1 个答案:

答案 0 :(得分: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);