Archive

Archive for February, 2016

Bizspark WSDL xsd=xsd2 error #solved

bizspark-logo

When connecting to a Bizspark based WSDL webservice (.svc) endpoint, via add service reference in visual studio (same error with WSDL.exe), then I got this error;

The document was understood, but it could not be processed.
– The WSDL document contains links that could not be resolved.
– There was an error downloading ‘?xsd=xsd2’.
– Unable to connect to the remote server
– A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

 

Now, I checked the WSDL, and it looked like valid XML, but I did see a reference to a URL that had a reference to a URL which had the ?xsd=xsd2 querystring, and didn’t actually go anywhere when I clicked it.

So, I then had a look at the webservice homepage again, and noticed that you can use an alternative WSDL document, which combines all the nested XSD’s in one: using ?singleWsdl  in the querystring.

 

 

 

 

Categories: Uncategorized

Key/Value storage using #Sqlite in #Cordova / #Phonegap

firebase
When offline data storage needs in a PhoneGap / Cordova application outgrow the 5Mb limits of LocalStorage, then you need to turn to Sqlite. However, this doesn’t mean that you have to redesign everything. Perhaps you are still happy with key/value storage. So, here’s two simple function calls to save and load data from a simple 2 column database table using Cordova / Phonegap and the plugin from litehelpers

 

function SqlStorageSetItem(key,value)
{
// Location 2 – not backed to iCloud
var db = window.sqlitePlugin.openDatabase({name: “sql.db”, location: 2}, function(){
console.log(“Opened database ok”);
}, function(err){
console.log(‘Open database ERROR: ‘ + JSON.stringify(err));
});

db.executeSql(“Create table if not exists keyValuePair (key,value);”,[], function(res){
console.log(“Created table if not already present”);
});

db.executeSql(“select key from keyValuePair where key='” + key + “‘”,[],function(res){
if (res.rows.length == 0)
{
console.log(“Key not present, inserting row”);
db.executeSql(“insert into keyValuePair (key,value) values (‘” + key + “‘,'” + value + “‘)”,[], function(res){
console.log(“Added ” + key + ” to keyValuePair database”);
});
}
else
{
db.executeSql(“update keyValuePair set value='” + value + “‘ where key = ‘” + key + “‘”,[], function(res){
console.log(“Updated ” + key + ” to keyValuePair database”);
});
}
});
}

function SqlStorageGetItem(key,callback)
{
// Location 2 – not backed to iCloud
var db = window.sqlitePlugin.openDatabase({name: “sql.db”, location: 2}, function(){
console.log(“Opened database ok”);
}, function(err){
console.log(‘Open database ERROR: ‘ + JSON.stringify(err));
});

db.executeSql(“select value from keyValuePair where key='” + key + “‘”,[],function(res){
if (res.rows.length == 0)
{
console.log(“No matching key found”);
callback(null);
}
else
{
console.log(“Key found”);
callback(res.rows.item(0).value);
}
});
}

The one key difference, is that the SqlStorageGetItem function is asynchronous, so you have to pass a callback to it, in order to get the value.

 

 

Categories: Uncategorized

Unofficial LinkedIn API in .NET (C#)

The LinkedIn API has of late been very much limited to very basic functionality, and you may want to get more information out of it.

I based this API on these two sources

// https://github.com/nickls/linkedin-unofficial-api

and

// https://www.tarlogic.com/blog/usuarios-y-direcciones-de-correo-con-linkedin-harverster/

Unfortunately, this code is actually not suitable as a web service or from a website, since LinkedIn will detect that the login request is coming from a unusual IP (location), and kick you out. But it would be useful for client-side code.

So, here’s the login code – at a high level

HttpOverTcpRequest http = new HttpOverTcpRequest();
var welcomeRaw = http.Request(“https://www.linkedin.com/uas/authenticate”);
var welcome = http.ParseHttpResponse(welcomeRaw);
var lCookies = welcome.Headers[“Set-Cookie”];
lCookies.RemoveAll(c => c.Contains(“delete me”) || c.Contains(“deleteMe”)); // Remove empty cookies
var jSessionIdRaw = lCookies.First(c => c.Contains(“JSESSIONID”));
var jSessionId = jSessionIdRaw.Split(new[] { ‘;’ })[0].Substring(12);
var postdata = “session_key=” + username + “&session_password=” + password + “&JSESSIONID=”+ jSessionId;
var loginRaw = http.Request(“https://www.linkedin.com/uas/authenticate”, postdata, lCookies);
var login = http.ParseHttpResponse(loginRaw);
var lCookies2 = login.Headers[“Set-Cookie”];
lCookies.AddRange(lCookies2);

Then, you need to keep hold of your lCookies array, and pass it back in when making requests such as;

// /li/v1/pages/you
var YouRaw = http.Request(“https://touch.www.linkedin.com/” + query, lCookiesFromDb);
var you = http.ParseHttpResponse(YouRaw);
var strJson = RemoveQuirks(you.Body);
Response.Write(strJson);

Categories: Uncategorized

Send Email via client-side Javascript

logo

Typically, if you want to send an Email via Javascript, like in response to a feedback form, or other client-side user interaction. Then you end up having to write server-side code to send the email, and then client side code to make an Ajax call to the server, or force the user to move to another page.

Tired of writing this code over and over again for every web project I did, and increasingly every Phonegap App I wrote, I decided to write a general script that can send an email from Javascript, with no server side code required. – and no dependencies, like jQuery.

So, here’e the website http://www.smtpjs.com 

It works as follows, you add a script reference to

http://smtpjs.com/smtp.js

Then you send the email like so…

Email.send("from@you.com",
"to@them.com",
"This is a subject",
"this is the body",
"smtp.yourisp.com",
"username",
"password");

But Wait!!!, I can hear you scream… My username and password are visible in client side script. – So The trick to this, is that you can encrypt the credentials on SMTPJS.com and receive a security token, and then use this to send the email instead.

In which case you can send Email as follows

Email.send("from@you.com",
"to@them.com",
"This is a subject",
"this is the body",
{token: "63cb3a19-2684-44fa-b76f-debf422d8b00"});


Which is much more secure, and we’d recommend this even if your code is packaged inside a Phonegap/Cordova App.

Categories: Uncategorized