我的第一个SOAP客户端中的异常

时间:2012-07-08 07:30:03

标签: php exception soap

我正在尝试为该服务编写SOAP客户端 https://webservice.kareo.com/services/soap/2.1/KareoServices.svc?wsdl

我查询了服务提供的类型(_ getTypes)和函数( _getFunctions)。下面是我正在尝试执行的'GetPatients'操作的类型结构:

struct GetPatients {
 GetPatientsReq request;
}

struct GetPatientsReq {
 PatientFieldsToReturn Fields;
 PatientFilter Filter;
}

struct PatientFieldsToReturn {
 boolean AddressLine1;
 boolean AddressLine2;
 boolean Age;
.
.
.
}

struct PatientFilter {
 string CollectionCategoryName;
 string DefaultCasePayerScenario;
 string FirstName;
.
.
.
}

struct GetPatientsResponse {
 GetPatientsResp GetPatientsResult;
}

struct GetPatientsResp {
 ArrayOfPatientData Patients;
}

struct ArrayOfPatientData {
 PatientData PatientData;
}

struct PatientData {
 string AddressLine1;
 string AddressLine2;
 string Adjustments;
 string Age;
.
.
.
}

功能定义是:

GetPatientsResponse GetPatients(GetPatients $ parameters)

下面是我的PHP代码,它试图使用Web服务的'GetPatients'操作:

    <?php

     $url="https://webservice.kareo.com/services/soap/2.1/KareoServices.svc?wsdl";

     $client=new SoapClient($url);

    /* fake user, password, key */

     $CustomerKey='xxx';

     $User='rmg15';

     $Password='pass77';

     $PatientID='1234';

    $authheader=array("CustomerKey"=>$CustomerKey,"User"=>$User,"Password"=>$Password);

    $header =  new SoapHeader("https://webservice.kareo.com/services/soap/2.1/","AuthHeader",  $authheader,false);

    $client->__setSoapHeaders(array($header));

    /* it works till this point because I was able to successfully perform the __getTypes, __getFunctions operations. */


   $filter= array("FirstName"=>"rmg15");

   $fields=array("age"=>"true");

   $request=array("PatientFieldsToReturn"=>$fields,"PatientFilter"=>$filter);

   $getpatientreq=array("GetPatientsReq"=>$request);

   try
  {
   $presponse=$client->GetPatients($getpatientreq);

  }

  catch (Exception $ex) {
   var_dump($ex->faultcode, $ex->faultstring, $ex->faultactor, $ex->detail, $ex->_name, $ex->headerfault);

   }

   ?>

这是我从服务中获得的例外:

“对象引用未设置为对象的实例。”

此行抛出异常:

$ presponse = $ client-&gt; GetPatients($ getpatientreq)

以下是整个异常消息:

object(stdClass)#7 (1) {
  ["ExceptionDetail"]=>
  object(stdClass)#8 (5) {
    ["HelpLink"]=>
    NULL
    ["InnerException"]=>
    NULL
    ["Message"]=>
    string(53) "Object reference not set to an instance of an object."
    ["StackTrace"]=>
    string(755) "   at KareoServicesWCF.KareoServices.GetPatients(GetPatientsReq request) in c:\BuildAgent\work\309fd08b06e24475\Superbill\Software\Application\KareoServicesWCF\2.1\KareoServicesWCF\KareoServices.cs:line 497
   at SyncInvokeGetPatients(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)"
    ["Type"]=>
    string(29) "System.NullReferenceException"

这是我写的第一个SOAP客户端。任何帮助解决这个问题都很有帮助。

1 个答案:

答案 0 :(得分:1)

找到解决方案。感谢Ankit Jain在http://cgeers.com/2009/08/20/using-wcf-services-with-php-5/

的回复
$wsdl = 'https://webservice.kareo.com/services/soap/2.1/KareoServices.svc?wsdl';

$client = new SoapClient($wsdl, array('trace' => 1, 'exceptions' => 1));

// Store data in the object of stdClass`enter code here`
$requestHeader = new stdClass;
$requestHeader->CustomerKey = 'xxx';
$requestHeader->User = 'yyy';
$requestHeader->Password = 'int123';

$filter = new stdClass;
$filter->PracticeName = "American Surgery Associates";


$fields = new stdClass;
$fields->ID = true;
$fields->PracticeName = true;
$fields->PatientFullName = true;

$request = new stdClass;
$request->RequestHeader = $requestHeader;
$request->Filter = $filter;
$request->Fields = $fields;

// Call a SOAP function
$response = $client->GetPatients(array('request' => $request));

    print_r($response);