title: PHP and Accessing ComplexType in SOAP Web Service
body: <p>I want to make a call to a webservice. And the webservice is contain some complextype elements. I'm getting good results with ASP.NET and soapUI. But I'm getting an error with PHP. I couldn't figured out.</p>
  
  <p>So, could you help me please?</p>
  
  <p>Thanks.</p>
  
  <p>The function I want to call:</p>
  
  <pre><code>&lt;xs:element name="GetHotelSearch"&gt;
    &lt;xs:complexType&gt;
       &lt;xs:sequence&gt;
          &lt;xs:element minOccurs="0" name="searchClass" nillable="true" type="q13:HotelSearch" xmlns:q13="http://schemas.datacontract.org/2004/07/Model"/&gt;
          &lt;xs:element minOccurs="0" name="recorCount" type="xs:int"/&gt;
          &lt;xs:element minOccurs="0" name="sortType" type="q14:SortType" xmlns:q14="http://schemas.datacontract.org/2004/07/Model"/&gt;
          &lt;xs:element minOccurs="0" name="sortFields" nillable="true" type="q15:ArrayOfSortField" xmlns:q15="http://schemas.datacontract.org/2004/07/Model"/&gt;
       &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  &lt;xs:element name="GetHotelSearchResponse"&gt;
    &lt;xs:complexType&gt;
       &lt;xs:sequence&gt;
          &lt;xs:element minOccurs="0" name="GetHotelSearchResult" nillable="true" type="q16:ArrayOfHotelSummary" xmlns:q16="http://schemas.datacontract.org/2004/07/Model"/&gt;
          &lt;xs:element minOccurs="0" name="recorCount" type="xs:int"/&gt;
       &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  </code></pre>
  
  <p>ComplexTypes:</p>
  
  <pre><code>   &lt;xs:complexType name="HotelSearch"&gt;
        &lt;xs:sequence&gt;
           &lt;xs:element minOccurs="0" name="BRANCHID" type="xs:int"/&gt;
           &lt;xs:element minOccurs="0" name="UNIQUECODE" nillable="true" type="xs:string"/&gt;
        &lt;/xs:sequence&gt;
     &lt;/xs:complexType&gt;
  
     &lt;xs:simpleType name="SortType"&gt;
        &lt;xs:restriction base="xs:string"&gt;
           &lt;xs:enumeration value="Ascending"&gt;
              &lt;xs:annotation&gt;
                 &lt;xs:appinfo&gt;
                    &lt;EnumerationValue xmlns="http://schemas.microsoft.com/2003/10/Serialization/"&gt;1&lt;/EnumerationValue&gt;
                 &lt;/xs:appinfo&gt;
              &lt;/xs:annotation&gt;
           &lt;/xs:enumeration&gt;
           &lt;xs:enumeration value="Descending"&gt;
              &lt;xs:annotation&gt;
                 &lt;xs:appinfo&gt;
                    &lt;EnumerationValue xmlns="http://schemas.microsoft.com/2003/10/Serialization/"&gt;2&lt;/EnumerationValue&gt;
                 &lt;/xs:appinfo&gt;
              &lt;/xs:annotation&gt;
           &lt;/xs:enumeration&gt;
        &lt;/xs:restriction&gt;
     &lt;/xs:simpleType&gt;
  
     &lt;xs:element name="SortType" nillable="true" type="tns:SortType"/&gt;
     &lt;xs:complexType name="ArrayOfSortField"&gt;
        &lt;xs:sequence&gt;
           &lt;xs:element minOccurs="0" maxOccurs="unbounded" name="SortField" type="tns:SortField"/&gt;
        &lt;/xs:sequence&gt;
     &lt;/xs:complexType&gt;
  
     &lt;xs:element name="ArrayOfSortField" nillable="true" type="tns:ArrayOfSortField"/&gt;
     &lt;xs:simpleType name="SortField"&gt;
        &lt;xs:restriction base="xs:string"&gt;
           &lt;xs:enumeration value="PENSIONTYPENAME"&gt;
              &lt;xs:annotation&gt;
                 &lt;xs:appinfo&gt;
                    &lt;EnumerationValue xmlns="http://schemas.microsoft.com/2003/10/Serialization/"&gt;1&lt;/EnumerationValue&gt;
                 &lt;/xs:appinfo&gt;
              &lt;/xs:annotation&gt;
           &lt;/xs:enumeration&gt;
           &lt;xs:enumeration value="HOTELNAME"&gt;
              &lt;xs:annotation&gt;
                 &lt;xs:appinfo&gt;
                    &lt;EnumerationValue xmlns="http://schemas.microsoft.com/2003/10/Serialization/"&gt;2&lt;/EnumerationValue&gt;
                 &lt;/xs:appinfo&gt;
              &lt;/xs:annotation&gt;
           &lt;/xs:enumeration&gt;
        &lt;/xs:restriction&gt;
     &lt;/xs:simpleType&gt;
     &lt;xs:element name="SortField" nillable="true" type="tns:SortField"/&gt;
  </code></pre>
  
  <p>.NET Code (it's working):</p>
  
  <pre><code>int _recordCount = 10;
  List&lt;HotelSummary&gt; hotels = hc.GetHotelSearch(new HotelSearch()
  {
      BRANCHID = 000,
      UNIQUECODE = "YIO"
  }, ref _recordCount, SortType.Ascending, new SortField[] { SortField.HOTELNAME }).ToList();
  </code></pre>
  
  <p>The XML (it's working with soapUI):</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:mod="http://schemas.datacontract.org/2004/07/Model"&gt;
     &lt;soapenv:Header/&gt;
     &lt;soapenv:Body&gt;
        &lt;tem:GetHotelSearch&gt;
           &lt;tem:searchClass&gt;
               &lt;mod:BRANCHID&gt;000&lt;/mod:BRANCHID&gt;
               &lt;mod:UNIQUECODE&gt;YIO&lt;/mod:UNIQUECODE&gt;
           &lt;/tem:searchClass&gt;
           &lt;tem:recorCount&gt;10&lt;/tem:recorCount&gt;
           &lt;tem:sortType&gt;Ascending&lt;/tem:sortType&gt;
           &lt;tem:sortFields&gt;
               &lt;mod:SortField&gt;HOTELNAME&lt;/mod:SortField&gt;
           &lt;/tem:sortFields&gt;
        &lt;/tem:GetHotelSearch&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>And PHP Code (It's not WORKING):</p>
  
  <pre><code>ini_set("soap.wsdl_cache_enabled", "0");
  
  $url='http://localhost/Service/Service.svc?wsdl';
  
  $client = new SoapClient($url);
  
  $HotelSearch= array('BRANCHID' =&gt; 000,'UNIQUECODE' =&gt; 'YIO');
  $SortField= array('SortField' =&gt; 'HOTELNAME');
  
  $result = $client-&gt;GetHotelSearch($HotelSearch, 10, 'Ascending', $SortField);
  
  $array = $result-&gt;GetHotelSearchResult-&gt;HotelSummary;
  </code></pre>
  
  <p>I'm getting this error:</p>
  
  <pre><code>Fatal error: Uncaught SoapFault exception: [a:InternalServiceFault] End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 155. in D:\[.Projeler]\musteri\webservis\test.php:98 Stack trace: #0 D:\[.Projeler]\musteri\webservis\test.php(98): SoapClient-&gt;__call('GetHotelSearch', Array) #1 D:\[.Projeler]\musteri\webservis\test.php(98): SoapClient-&gt;GetHotelSearch(Array, 10, 'Ascending', Object(stdClass)) #2 {main} thrown in D:\[.Projeler]\musteri\webservis\test.php on line 98 
  </code></pre>
  
  <p>With try and catch:</p>
  
  <pre><code>End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 155.
  </code></pre>