使用Soapclient调用Soap Web服务

时间:2014-09-29 13:14:49

标签: php web-services soap web soap-client

我第一次做SOAP api任务。我需要从TriSource调用SOAP api,如下所示。

我无法弄清楚下面的代码有什么问题。

<?php

$wsdl = "https://www.nobel-net.com/TSS_LOAD/TSS_LOAD.asmx?WSDL";// getcwd().'/TriSource.wsdl';
$options        = array('soap_version' => SOAP_1_2, 'trace' => 1, 'exceptions' => 1);
$client = new SoapClient($wsdl, $options);
// output of : var_dump($client->__getFunctions());
// array (size=4)
//  0 => string 'SandboxResponse Sandbox(Sandbox $parameters)' (length=44)
//  1 => string 'BoardResponse Board(Board $parameters)' (length=38)
//  2 => string 'SandboxResponse Sandbox(Sandbox $parameters)' (length=44)
//  3 => string 'BoardResponse Board(Board $parameters)' (length=38)
$xmlBody = 'this is a long xml stirng';

try
{
   $args = new SoapVar(new SoapVar($xmlBody, XSD_ANYXML),SOAP_ENC_OBJECT);

   // alternate try
   // $args = array(new SoapVar($xmlBody, XSD_ANYXML));

  $res = $client->Sandbox($args);
}
catch (SoapFault $e)
{
   var_dump($e);
}

我总是得到如下的Soap故障。

object(SoapFault)[4]
 protected 'message' => string 'System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> TSS_Load+ProgramError: Error writing Usage log.
 Object reference not set to an instance of an object.

 at TSS_Load.XML_Reader.AddLog(String Usage, String UserID, String Result, String Data) in c:\inetpub\wwwroot\TSS_LOAD\App_Code\TSS_Load.cs:line 3365
 at TSS_Load.Sandbox(String sData) in c:\inetpub\wwwroot\TSS_LOAD\App_Code\TSS_Load.cs:line 44
 --- End of inner exception stack trace ---' (length=485)

1 个答案:

答案 0 :(得分:0)

我发现了自己的错误。 我正在以错误的方式准备SOAP参数。 根据wsdl,Sandbox类型如下所示。

// Class with sData string member
class Sandbox
{
  string sData;
}

SOAP变量,如下所示。

// PHP code
$args = array('sData'=>new SoapVar($xmlBody, XSD_ANYXML));