Archive
Uncaught SoapFault exception: [Sender] SOAP-ERROR: Encoding: Violation of encoding rules

WTF?, why the hell is every PHP developer saying my webservice is returning Uncaught SoapFault exception: [Sender] SOAP-ERROR: Encoding: Violation of encoding rules – and there’s no problem with those using .NET, or parsing the XML response over HTTP GET/POST
Ok, let’s break down the problem.
1. It’s not a problem with PHP,it’s your WSDL, so here’s how to diagnose it.
Take this simple code snippet
$client = new SoapClient(“http://www.regcheck.org.uk/api/reg.asmx?wsdl”);
$params = array (
“RegistrationNumber” => “TNZ6972”,
“username” => “**Your Username**”
);
$response = $client->__soapCall(‘Check’, array($params));
print_r($response);
Now, take a copy of the WSDL, and save it as a text file, so you can edit it easily, i.e.
http://www.regcheck.org.uk/php.wsdl , then using HTML style comments, take out everything you can until you get a minimum working version. – i.e. a call that returns “something“, not all the data, but “something”
<s:complexType name=”Vehicle“>
I had a hunch it was the VehicleData object, since it was the most complex type in the response, so I commented that out – and I now had a minimum working version.
After that, I progressively commented out elements within the VehicleData type, until I got my maximum working version – i.e. as much data as possible without it breaking.
At that point, I hit upon this:
<s:element minOccurs=”0″ maxOccurs=”1″ name=”CarModel”> <s:complexType> <s:simpleContent> <s:extension base=”s:integer“> <s:attribute name=”type” type=”s:NCName” /> </s:extension> </s:simpleContent> </s:complexType> </s:element>
Which was the point at which the webservice stopped returning data, and starting throwing the Uncaught SoapFault exception: [Sender] SOAP-ERROR: Encoding: Violation of encoding rules – and it did look odd, since I new that “CarModel” should be a string, not an integer.
Looking at the underlying C# code, the error was obvious
[System.Xml.Serialization.XmlTextAttribute(DataType=”integer“)]
public string Value {
There is no way that Value could both be a string and an integer, so I changed it to
[System.Xml.Serialization.XmlTextAttribute()]
public string Value {
#Base64 decode using #SQL server #UDF

Base64 is a way to encode data into a limited character set, that can allow binary data to be displayed using print-friendly text. For example, if you wanted to represent an image as text, and store it in a database. It does bloat data, but it’s certainly handy when it comes to passing data around.
SQL server doesn’t have a handy function to convert base64 text back into it’s original form, so I decided to write this UDF below;
CREATE FUNCTION dbo.Base64Decode (@Base64 varchar(max))
RETURNS varchar(max)
WITH SCHEMABINDING AS
BEGIN
DECLARE @TEXT AS varchar(max) ;
SELECT
@TEXT = CAST( CAST( @Base64 as XML ).value(‘.’,’varbinary(max)’) AS varchar(max) );RETURN @TEXT ;
END;
GO
#Stuck #App #Roadside assistance in #Australia @stuck_app

Stuck is a new app for Australian drivers which you can download for iOS or Android via their website here;https://stuck.com.au/
Stuck is an on-demand service which calls local automotive experts to the rescue, saving you an annual insurance-style roadside assistance membership. Here’s how it works:
1. Share your required service and location with local, accredited automotive experts. The nearest available expert will arrive to help as soon as possible.
2. You are given the price upfront, which is usually about half the cost of a normal annual membership. Any extras can be added on if required (such as a new tyre).
3. Once your car problem is resolved, payment happens automatically without paperwork. Finally, you provide feedback to the automotive expert and get going!
From a technical point of view, it uses our Australian Car Registration API http://www.carregistrationapi.com/
#MachineLearning using #Microsoft Azure

Me: Azure , what is 1 + 1 ?
Azure: It’s 1.999999999992212
Me: No it’s not.
Azure: Come on, I’m almost right!
I’ve just been playing with the Azure Machine Learning Studio, to see if it could be accurate enough for practical applications. The most simple example I could think of was a model where it was given 1,000 examples of one number, followed by a second number which was one greater.
1,2
2,3
3,4
You can see the model in the Cortana Intellegence Gallery here
https://gallery.cortanaintelligence.com//Experiment/Plus-one-webservice-1
Interestingly, the result is not perfect as would be expected, but it goes wrong in a way that only a machine would think is close to the correct answer.

#Verify a #BankAccount via an #API

If you process large volumes of payments, then you will need to be able to quickly and cheaply check that the payment you are about to make is going to a valid bank account, or else it will delay payment to your supplier / employee / or affiliate, this API allows you to check each account for 3p / 4¢ – using the same technology as used by Stripe.
verifyBankAccount.com
Getting started
The API endpoint is located at https://verifybankaccount.com/api.asmx
It accepts GET / POST and SOAP requests, and returns either a HTTP 500 error with textual description on error, or JSON embedded in XML in the case of a valid response, similar to as follows:
| <string xmlns=”http://verifybankaccount.com/”>
{ </string> |
Countries supported by this API are as follows;
| Country code | |
| US | USA |
| IE | Ireland |
| GB | United Kingdom |
| AU | Australia |
| CA | Canada |
| DK | Denmark |
| FI | Finland |
| FR | France |
| JP | Japan |
| NO | Norway |
| SG | Singapore |
| ES | Spain |
| SE | Sweden |
| AT | Austria |
| BE | Belgium |
| DE | Germany |
| HK | Hong Kong |
| IT | Italy |
| LU | Luxembourg |
| NL | Netherlands |
| PT | Portugal |
The API also includes an endpoint for programmatically retrieving the remaining credits associated with an API Key, called GetRemainingCredit returning data such as;
| <int xmlns=”http://verifybankaccount.com/”>98</int> |
C# (.NET) implementation
Here is a step by step guide to writing a simple C# client
- Open Visual Studio
- Press File > New > Project
- Select Console Application – Visual C#
- Press OK
- Right Click on the project in Solution Explorer
- Select Add > Service Reference
- Click Advanced
- Click Add Web Reference
- Enter “https://www.verifybankaccount.com/api.asmx?wsdl” into the URL
- Press Add Reference
- Click Tools > NuGet Package Manager > Package Manager Console
- Type “Install-Package Newtonsoft.JSON” into the Package Manager Console window
- Now, enter the following code (Replacing the API KEY)
| static void Main(string[] args)
{ var strAPIKey = “Your API key here“; var bank = new com.verifybankaccount.www.API(); Console.WriteLine(“Enter the 2 letter country code:”); var strCountry = Console.ReadLine(); Console.WriteLine(“Enter the Bank sort code:”); var strSortCode = Console.ReadLine(); Console.WriteLine(“Enter the Bank account number:”); var strAccountNumber = Console.ReadLine(); try { var strJson = bank.VerifyBankAccount(strCountry, strSortCode, strAccountNumber, strAPIKey); var jObject = Newtonsoft.Json.Linq.JObject.Parse(strJson); Console.WriteLine(“This bank is ” + jObject[“bank_name”]); } catch(Exception ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); } |
PHP Implementation
The following implementation uses the HTTP GET version of the webservice, you could use $soapclient as an alternative implementation. Please note that you should never pass bank account details over an unsecure connection so this code should be run either on localhost or on a suitably secured HTTPS webserver.
You will have to replace the APIKey below
| <?php
$country = $_GET[“country”]; $sortcode = $_GET[“sortcode”]; $accountNumber = $_GET[“accountNumber”]; $url = “https://www.verifybankaccount.com/api.asmx /VerifyBankAccount?”; $url .= “Country=” . $country; $url .= “&SortCode=” . $sortcode; $url .= “&AccountNumber=” . $accountNumber; $url .= “&ApiKey={{Your API Key}}“; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $xmlData = curl_exec($ch); libxml_use_internal_errors(true); $xml=simplexml_load_string($xmlData); if ($xml) { $json = json_decode($xml); print_r($json->bank_name); } else { print_r($xmlData); } ?> |