title: Exception in my first SOAP client
body: <p>I'm trying to write a SOAP client for the service at 
  <a href="https://webservice.kareo.com/services/soap/2.1/KareoServices.svc?wsdl" rel="nofollow">https://webservice.kareo.com/services/soap/2.1/KareoServices.svc?wsdl</a> </p>
  
  <p>I queried the types (_<em>getTypes) and functions (</em>_getFunctions) that the service offers . Below is the type structure for the 'GetPatients' operation I'm trying to perform:</p>
  
  <pre><code>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;
  .
  .
  .
  }
  </code></pre>
  
  <p>The function definition is:</p>
  
  <p>GetPatientsResponse GetPatients(GetPatients $parameters)</p>
  
  <p>Below is my php code that tries to use the web service's 'GetPatients' operation:</p>
  
  <pre><code>    &lt;?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"=&gt;$CustomerKey,"User"=&gt;$User,"Password"=&gt;$Password);
  
      $header =  new SoapHeader("https://webservice.kareo.com/services/soap/2.1/","AuthHeader",  $authheader,false);
  
      $client-&gt;__setSoapHeaders(array($header));
  
      /* it works till this point because I was able to successfully perform the __getTypes, __getFunctions operations. */
  
  
     $filter= array("FirstName"=&gt;"rmg15");
  
     $fields=array("age"=&gt;"true");
  
     $request=array("PatientFieldsToReturn"=&gt;$fields,"PatientFilter"=&gt;$filter);
  
     $getpatientreq=array("GetPatientsReq"=&gt;$request);
  
     try
    {
     $presponse=$client-&gt;GetPatients($getpatientreq);
  
    }
  
    catch (Exception $ex) {
     var_dump($ex-&gt;faultcode, $ex-&gt;faultstring, $ex-&gt;faultactor, $ex-&gt;detail, $ex-&gt;_name, $ex-&gt;headerfault);
  
     }
  
     ?&gt;
  </code></pre>
  
  <p>This is the exception I'm getting from the service:</p>
  
  <p>"Object reference not set to an instance of an object."</p>
  
  <p>The exception is thrown at this line: </p>
  
  <p>$presponse=$client->GetPatients($getpatientreq)                 </p>
  
  <p>Here is the entire exception message: </p>
  
  <pre><code>object(stdClass)#7 (1) {
    ["ExceptionDetail"]=&gt;
    object(stdClass)#8 (5) {
      ["HelpLink"]=&gt;
      NULL
      ["InnerException"]=&gt;
      NULL
      ["Message"]=&gt;
      string(53) "Object reference not set to an instance of an object."
      ["StackTrace"]=&gt;
      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[]&amp; outputs)
     at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)"
      ["Type"]=&gt;
      string(29) "System.NullReferenceException"
  </code></pre>
  
  <p>This is the first SOAP client I'm writing. Any help in fixing this will be useful. </p>