I have a PHP script that sends a SOAP request to : https://securedwebapp.com/api/service.asmx?WSDL which is the API entry point for KashFlow.com accounting software. The SOAP API states the following request format :
<s:complexType name="Invoice">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="InvoiceDBID" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="InvoiceNumber" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="InvoiceDate" type="s:dateTime"/>
<s:element minOccurs="1" maxOccurs="1" name="DueDate" type="s:dateTime"/>
<s:element minOccurs="0" maxOccurs="1" name="Customer" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="CustomerID" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="Paid" type="s:int"/>
<s:element minOccurs="0" maxOccurs="1" name="CustomerReference" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="EstimateCategory" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="SuppressTotal" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="ProjectID" type="s:int"/>
<s:element minOccurs="0" maxOccurs="1" name="CurrencyCode" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="ExchangeRate" type="s:decimal"/>
<s:element minOccurs="0" maxOccurs="1" name="ReadableString" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Lines" type="tns:ArrayOfAnyType"/>
<s:element minOccurs="1" maxOccurs="1" name="NetAmount" type="s:decimal"/>
<s:element minOccurs="1" maxOccurs="1" name="VATAmount" type="s:decimal"/>
<s:element minOccurs="1" maxOccurs="1" name="AmountPaid" type="s:decimal"/>
<s:element minOccurs="0" maxOccurs="1" name="CustomerName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="PermaLink" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="DeliveryAddress" type="tns:DeliveryAddress"/>
<s:element minOccurs="1" maxOccurs="1" name="UseCustomDeliveryAddress" type="s:boolean"/>
</s:sequence>
</s:complexType>
And using __getLastRequest I can see the following SOAP request being sent
SOAP Headers :
Dumping results from SOAP :__getLastRequestHeaders
POST /api/service.asmx HTTP/1.1
Host: securedwebapp.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/7.2.20-2+0~20190725.24+debian9~1.gbp69697c
Content-Type: text/xml; charset=utf-8
SOAPAction: "KashFlow/InsertInvoice"
Content-Length: 828
Dumping results from SOAP :__getLastRequest
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="KashFlow">
<SOAP-ENV:Body>
<ns1:InsertInvoice>
<ns1:UserName>MyUserName</ns1:UserName>
<ns1:Password>MyPassword</ns1:Password>
<ns1:Inv>
<ns1:InvoiceDBID/>
<ns1:InvoiceNumber>2</ns1:InvoiceNumber>
<ns1:InvoiceDate>20190608T00:00:00</ns1:InvoiceDate>
<ns1:DueDate>20190608T00:00:00</ns1:DueDate>
<ns1:CustomerID>81226309</ns1:CustomerID>
<ns1:Paid>0</ns1:Paid>
<ns1:SuppressTotal>0</ns1:SuppressTotal>
<ns1:ProjectID/>
<ns1:ExchangeRate>1</ns1:ExchangeRate>
<ns1:NetAmount>32.5</ns1:NetAmount>
<ns1:VATAmount>32.5</ns1:VATAmount>
<ns1:AmountPaid>0</ns1:AmountPaid>
<ns1:UseCustomDeliveryAddress>false</ns1:UseCustomDeliveryAddress>
</ns1:Inv>
</ns1:InsertInvoice>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The error that I am getting back is :
SOAP Response Headers :
Dumping results from SOAP :__getLastResponseHeaders
HTTP/1.1 500 Internal Server Error
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
P3P: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"
Date: Tue, 30 Jul 2019 11:15:47 GMT
Content-Length: 585
SOAP Response Body :
Dumping results from SOAP :__getLastResponse
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (2, 261). ---> System.FormatException: Input string was not in a correct format.
</faultstring>
<detail/>
</soap:Fault>
</soap:Body>
</soap:Envelope>
I am unable to work out what is wrong, the response body states error in XML (2, 261) but i cant work out what this actually relates to, is it a character count from '< ?xml' in the request body, or is it a count from '< SOAP-ENV' also why the 2 numbers?
The above output has been stripped down from my original full SOAP request to the minimum that can be sent (I am not posting any 'Lines' while debugging, also I have tried both NULL and a unique number for 'InvoiceNumber'.
Any KashFlow or SOAP people able to point me in the correct direction to fix this issue? Also any extra pointers for debugging SOAP requests in the future would be great.
I have cleared the local SOAP cache, and have confirmed that leaving out a required field in the request results in a different error code being returned that states the field is missing.