0

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

我查询了服务提供的类型(_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)

下面是我尝试使用 Web 服务的“GetPatients”操作的 php 代码:

    <?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->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 客户端。解决此问题的任何帮助都会很有用。

4

1 回答 1

1

找到了解决方案。感谢 Ankit Jain 在https://github.com/geersch/WcfServicesWithPhp5的回复

$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);
于 2012-07-12T16:40:52.643 回答