簡體   English   中英

使用Soapclient調用Soap Web服務

[英]Call Soap webservices using Soapclient

我正在做第一次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)

我發現了我的錯誤。 我以錯誤的方式准備SOAP參數。 按照wsdl,沙盒類型如下。

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

如下所示的SOAP變量。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM