title: Convert C# to PHP
body: <p>I am accessing a webservice using SOAP and PHP. I can connect to a number of functions through to webservice API. But one eludes me. I have an example but it is in C#.</p>
  
  <p>I have tried to emulate the example in PHP with no luck.</p>
  
  <p>I have attached the C# code and my attempt in PHP. Also the error message are included.</p>
  
  <p><strong>C# code</strong></p>
  
  <pre><code> public void MakeSale()
   {
       string yourKey = "your key";
       using(DdDSaleService.SaleServiceClient client = new SaleServiceClient())
       {
           Sale sale = client.StartSale();
           //header info
           sale.ClientNumber = 996001;
           sale.Date = DateTime.Now;
           sale.Employee = 1;
           sale.NoteID = 123;
           sale.Terminal = 1;
           sale.Type = SaleType.Sale;
  
           //items in basket.
           ItemLine line1 = new ItemLine();
           line1.Type = ItemLineType.Sale;
           line1.ItemGroup = 1;
           line1.Supplier = 1;
           line1.Qty = 3;  //should -3 if a return of goods.
           line1.LineAmount = 600;  //The normal amount of the goods.
           line1.EDBNumber = 1; //unique key in our system. You have this if you got the articles by our service.
           line1.DiscountAmount = -100;  //the discount.
  
           //line2 comes here....
  
           //add the lines to the sale
           sale.ItemLines = new ItemLine[] { line1 };
  
           //The payment lines
           //1 with cash, and one with the change. the sale MUST sum to zero (itemlines + paymentlines)
           PaymentLine cash = new PaymentLine();
           cash.Type = PaymentLineType.Cash;
           cash.Qty = 1;
           cash.LineAmount = 600;
  
           PaymentLine change = new PaymentLine();
           change.Type = PaymentLineType.Change;
           change.Qty = 1;
           change.LineAmount = -100;
  
           //add the paymentlines
           sale.PaymentLines = new PaymentLine[]{cash,change};
  
           //submit the sale.
           Status response = client.SaveSale(sale, yourKey);
           Console.WriteLine(string.Format("got response from save sale saved: {0}, message: {1}",response.Saved,response.Message));
           Console.ReadLine();
      }
  }
  </code></pre>
  
  <p><strong>PHP code</strong></p>
  
  <pre><code>$client = new SoapClient("http://xxx.xxxxx.xxxx/xxxxxxx.svc?wsdl", array("trace" =&gt; 1, "connection_timeout" =&gt; 500));
  
  // Initialize sale
  // $client is a valid SOAP connection
  // That has been setup earlier
  $Sale = $client-&gt;StartSale();
  
  // Output what initalize sale returns
  print_r($Sale);
  
  // Format order date/time
  $timezone = new DateTimeZone("Europe/Copenhagen");
  $date = new DateTime("now", $timezone);
  $order_date_time = $date-&gt;format("Y-m-d\TH:i:s");
  
  // Set header information
  $Sale-&gt;StartSaleResult-&gt;ClientNumber = 996001;
  $Sale-&gt;StartSaleResult-&gt;Date = $order_date_time;
  $Sale-&gt;StartSaleResult-&gt;Employee = 1;
  $Sale-&gt;StartSaleResult-&gt;NoteID = 123;
  $Sale-&gt;StartSaleResult-&gt;Terminal = 1;
  $Sale-&gt;StartSaleResult-&gt;Type = 'Sale';
  
  // Itemline
  $line = new stdClass();
  $line-&gt;Type = 'Sale';
  $line-&gt;ItemGroup = 1;
  $line-&gt;Supplier = 1;
  $line-&gt;Qty = 3;
  $line-&gt;LineAmount = 600;
  $line-&gt;EDBNumber = 1;
  $line-&gt;DiscountAmount = 1-100;
  $Sale-&gt;StartSaleResult-&gt;ItemLines-&gt;ItemLine[] = $line;
  
  // Payment line, cash
  $cash = new stdClass();
  $cash-&gt;Type = 'Cash';
  $cash-&gt;Qty = 1;
  $cash-&gt;LineAmount = 600;
  $Sale-&gt;StartSaleResult-&gt;PaymentLines-&gt;PaymentLine[] = $cash;
  
  // Payment line, Change
  $change = new stdClass();
  $change-&gt;Type = 'Change';
  $change-&gt;Qty = 1;
  $change-&gt;LineAmount = -100;
  $Sale-&gt;StartSaleResult-&gt;PaymentLines-&gt;PaymentLine[] = $change;
  
  // Save sale
  $response = $client-&gt;SaveSale($Sale-&gt;StartSaleResult, 'xxxxxxxx');
  
  print_r($response);
  </code></pre>
  
  <p><strong>Output what webservice returns when connecting</strong></p>
  
  <pre><code>print_r($Sale);
  
  stdClass Object
  (
      [ClientNumber] =&gt; 0
      [Date] =&gt; 0001-01-01T00:00:00
      [Employee] =&gt; 0
      [ItemLines] =&gt; stdClass Object
          (
          )
  
      [NoteID] =&gt; 0
      [PaymentLines] =&gt; stdClass Object
          (
          )
  
      [Terminal] =&gt; 0
      [Type] =&gt; Sale
  )
  </code></pre>
  
  <p><strong>Error message</strong></p>
  
  <pre><code>    [previous:Exception:private] =&gt; 
      [faultstring] =&gt; End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 149.
      [faultcode] =&gt; a:InternalServiceFault
      [detail] =&gt; stdClass Object
          (
              [ExceptionDetail] =&gt; stdClass Object
                  (
                      [HelpLink] =&gt; 
                      [InnerException] =&gt; 
                      [Message] =&gt; End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 149.
                      [StackTrace] =&gt;    at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
     at System.Xml.XmlExceptionHelper.ThrowEndElementExpected(XmlDictionaryReader reader, String localName, String ns)
     at System.Xml.XmlBaseReader.ReadEndElement()
     at System.ServiceModel.Channels.Message.ReadFromBodyContentsToEnd(XmlDictionaryReader reader, EnvelopeVersion envelopeVersion)
     at System.ServiceModel.Channels.Message.ReadFromBodyContentsToEnd(XmlDictionaryReader reader)
     at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
     at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)
     at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp; rpc)
     at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
                      [Type] =&gt; System.Xml.XmlException
                  )
  
          )
  </code></pre>