Search This Blog

Wednesday, April 10, 2013

android - How to post data to not verified SSL url

the next code snippets will  allow you to make HTTPS call to non verified SSL certificate.

 HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;  
 HttpClient client = new DefaultHttpClient();  
 SchemeRegistry registry = new SchemeRegistry();  
 SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();  
 socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);  
 registry.register(new Scheme("https", socketFactory, 443));  
 SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);  
 DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());  
 HttpPost post = new HttpPost("https://www.yaniv.co.il/tst/IsValidUser.php");  
 List<NameValuePair> pairs = new ArrayList<NameValuePair>();  
 pairs.add(new BasicNameValuePair("user_name", user));  
 pairs.add(new BasicNameValuePair("password", pwd));  
 pairs.add(new BasicNameValuePair("type", type));                 
 post.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8));  
 HttpParams params = new BasicHttpParams();  
 int timeoutConnection = 5000;  
 HttpConnectionParams.setConnectionTimeout(params, timeoutConnection);  
 post.setParams(params);  
 HttpResponse response = httpClient.execute(post);  

be aware ,its not safe to make calls to non verified ssl, unless you know what are you doing.

enjoy
yaniv tzanany

Thursday, April 4, 2013

ASP.NEW web service creation - top down

sometime you want to create a mockup web service based on wsdl files that you get from the client.
the client sent to you the wsdl file , because he not allowed to access to his domain while developing the solution.

the easy way to create such service is with in your domain for testing.
you can do so via wsdl.exe program that ship with MS VS2008/2012 (Visual Studio 2008 Command Prompt).

if you have external xsd file that linked from the wsdl , add it to the command after the wsdl file.

e.g.
wsdl.exe my_demo.wsdl my_demo.xsd /l:CS /serverInterface /out:D:\MyStuff\ServerGenCode

the above command generates the interface file is D:\MyStuff\ServerGenCode directory based on the wsdl file and the xsd.

after generating the interface file , you need to implement the interface
e.g.
public class WebTestService : System.Web.Services.WebService, IMyDemo
{

    #region IMyDemo Members
    [WebMethod]
    public string GetName()
    {
     return "It Works !!!!";
    }
    #endregion 
}

enjoy
Yaniv Tzanany