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

Tuesday, March 19, 2013

Asynchronous Web Service Calls over HTTP with the .NET Framework

very informative article , contains description and several implantation Asynchronous Web Service Calls over HTTP with the .NET Framework: "Asynchronous Web Service Calls over HTTP with the .NET Framework"

on the same subject

Calling Web Services Asynchronously 



Saturday, March 16, 2013

AXIS C++ - starter kit for client on windows- WS from C++

To call Webservice from C++ (VC6 in may case) consider using AXIS C++ - gSoap is also a good option.

before starting your code , its very important to set the axis c++ correctly, i get many "system exception" until i figure out that i need to set the environment  properly.

after downloading your version  (axis-c-1.6b-Win32-trace-bin) and extract it.
set the this environment  variable:
  • AXISCPP_DEPLOY=D:\MyStuff\axis-c++\axis-c-1.6b-Win32-trace-bin\ -- [ your path]
  • add %AXISCPP_DEPLOY%\bin to your PATH.
  • download  - xerces 2.2  , grab the dll from the bin directory and put it in the %AXISCPP_DEPLOY%\bin directory.
  • Create file axiscpp.conf at %AXISCPP_DEPLOY%
in the file set the next rows - use full path:
#ClientLogPath is for axis trace - leave empty in case you dont want
ClientLogPath:D:\MyStuff\axis-c++\axis-c-1.6b-Win32-trace-bin\logs\AxisLog.txt
XMLParser:D:\MyStuff\axis-c++\axis-c-1.6b-Win32-trace-bin\bin\AxisXMLParserXerces.dll
Transport_http:D:\MyStuff\axis-c++\axis-c-1.6b-Win32-trace-bin\bin\HTTPTransport.dll
Channel_HTTP:D:\MyStuff\axis-c++\axis-c-1.6b-Win32-trace-bin\bin\HTTPChannel.dll
Channel_HTTP_SSL:D:\MyStuff\axis-c++\axis-c-1.6b-Win32-trace-bin\bin\HTTPSSLChannel.dll

you are done - its configured properly.
to create your C++ classes from WSDL:
  • get the wsdl 
  • open cmd windows
  • set the classpath 
    • e.g set CLASSPATH=D:\MyStuff\axis-c++\axis-c-1.6b-Win32-trace-bin\lib\axis\wsdl2ws.jar;D:\MyStuff\axis-c++\axis-c-1.6b-Win32-trace-bin\lib\axisjava\axis.jar;D:\MyStuff\axis-c++\axis-c-1.6b-Win32-trace-bin\lib\axisjava\commons-discovery.jar;D:\MyStuff\axis-c++\axis-c-1.6b-Win32-trace-bin\lib\axisjava\commons-logging.jar;D:\MyStuff\axis-c++\axis-c-1.6b-Win32-trace-bin\lib\axisjava\jaxrpc.jar;D:\MyStuff\axis-c++\axis-c-1.6b-Win32-trace-bin\lib\axisjava\saaj.jar;D:\MyStuff\axis-c++\axis-c-1.6b-Win32-trace-bin\lib\axisjava\wsdl4j.jar
  • run the command 
    • java org.apache.axis.wsdl.wsdl2ws.WSDL2Ws any_wsdl.wsdl -lc++ -sclient
you should see your header/cpp files in the directory.

happy coding 
Yaniv Tzanany