我正在尝试为 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 客户端。解决此问题的任何帮助都会很有用。