I am accessing a web service using SOAP and PHP. I can connect to several functions through the webservice API. But it eludes me. I have an example, but it is in C #.
I tried to imitate the example in PHP with no luck.
I have attached the C # code and my attempt in PHP. An error message is also included.
C # code
public void MakeSale() { string yourKey = "your key"; using(DdDSaleService.SaleServiceClient client = new SaleServiceClient()) { Sale sale = client.StartSale();
Php code
$client = new SoapClient("http://xxx.xxxxx.xxxx/xxxxxxx.svc?wsdl", array("trace" => 1, "connection_timeout" => 500)); // Initialize sale // $client is a valid SOAP connection // That has been setup earlier $Sale = $client->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->format("Ymd\TH:i:s"); // Set header information $Sale->StartSaleResult->ClientNumber = 996001; $Sale->StartSaleResult->Date = $order_date_time; $Sale->StartSaleResult->Employee = 1; $Sale->StartSaleResult->NoteID = 123; $Sale->StartSaleResult->Terminal = 1; $Sale->StartSaleResult->Type = 'Sale'; // Itemline $line = new stdClass(); $line->Type = 'Sale'; $line->ItemGroup = 1; $line->Supplier = 1; $line->Qty = 3; $line->LineAmount = 600; $line->EDBNumber = 1; $line->DiscountAmount = 1-100; $Sale->StartSaleResult->ItemLines->ItemLine[] = $line; // Payment line, cash $cash = new stdClass(); $cash->Type = 'Cash'; $cash->Qty = 1; $cash->LineAmount = 600; $Sale->StartSaleResult->PaymentLines->PaymentLine[] = $cash; // Payment line, Change $change = new stdClass(); $change->Type = 'Change'; $change->Qty = 1; $change->LineAmount = -100; $Sale->StartSaleResult->PaymentLines->PaymentLine[] = $change; // Save sale $response = $client->SaveSale($Sale->StartSaleResult, 'xxxxxxxx'); print_r($response);
Print web service is returned when connected
print_r($Sale); stdClass Object ( [ClientNumber] => 0 [Date] => 0001-01-01T00:00:00 [Employee] => 0 [ItemLines] => stdClass Object ( ) [NoteID] => 0 [PaymentLines] => stdClass Object ( ) [Terminal] => 0 [Type] => Sale )
Error message
[previous:Exception:private] => [faultstring] => End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 149. [faultcode] => a:InternalServiceFault [detail] => stdClass Object ( [ExceptionDetail] => stdClass Object ( [HelpLink] => [InnerException] => [Message] => End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 149. [StackTrace] => 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& rpc) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet) [Type] => System.Xml.XmlException ) )
c # soap php soap-client
Cudos
source share