This tutorial outlines difference (comparison) between WSClient++ and KSoap tool to connect web services.

Sample Web Service

Lets consider a very simple web service, that will return simple “Hello World” string.

KSoap Web Service Call for Android

KSoap2 Call on Android
  1. private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
  2. private static final String METHOD_NAME = "HelloWorld";
  3. private static final String NAMESPACE = "http://tempuri.org/";
  4. private static final String URL = "http://localhost/TestWeb/WebService.asmx";
  5.  
  6. public object GetResponse() throws Exception
  7. {
  8.     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
  9.     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  10.     envelope.dotNet=true;
  11.     envelope.setOutputSoapObject(request);
  12.  
  13.     HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
  14.  
  15.     androidHttpTransport.call(SOAP_ACTION, envelope);
  16.  
  17.     Object result = (Object)envelope.getResponse();
  18. }

Wow, you can see just to call one method, there is 18 lines of code. Well unfortunately you have to write this manually.

WSClient++ Web Service call for Android

WSClient++ generates source code that does all SOAP parsing/encoding for you on the fly. And the code that you have to use in your project will be as small as below,

WSClient++ call on Android
  1. public object GetResponse() throws Exception
  2. {
  3.     HelloWorldService service = new HelloWorldService();
  4.     service.setBaseUrl("http://localhost");
  5.     return service.HelloWorld();
  6. }

The total lines of code is now 6, and that too, actual service call is as small as just one line. However, in order to write KSoap call on asynchronous, you have to wrap your code around AsyncTask and write more code, where else with WSClient++ it is very easy to write asynchronous call, which works perfect without any hassle.

Async call on Android
  1. public void GetResponseAsync() throws Exception
  2. {
  3.     HelloWorldService service = new HelloWorldService();
  4.     service.setBaseUrl("http://localhost");
  5.     service.HelloWorld(
  6.         new service.HelloWorldResponse(
  7.             {
  8.                 public void onResult(string s){
  9.  
  10.                 }
  11.                 public void onError(Exception ex){
  12.  
  13.                 }
  14.             }
  15.     )
  16.     );
  17. }

Comparison

  WSClient++ KSoap
Automatic Code Generator YES NO
Automatic Type (Class) generation for every Soap Input/Output YES NO
Class with IParcelable Implementation YES NO
On the fly Encoding YES NO
Memory Footprint Small Big
Execution Time on Client Small Big
.NET Service Call Detection Auto Manual
Automatic Asynchronous Call Class Generator YES NO
Share
Tagged with:
 

This tutorial outlines how to call Soap Web Services from iOS or Mac OS XCode Projects in just few steps using Native Objective-C libraries and additional source code provided by WSClient++.

Code Generation

First step is to generate code from the available wsdl location. WSDL is Web Service Description Language specified in XML, which allows us to interpret schema used in transfer of objects between local and remote endpoints. To generate code, open WSClient++ and create a new configuration file which will specify WSDL URL, Folder to store generated files and select type as Objective-C and choose iOS or Mac OS as per your choice. As shown in following picture.

WSClientCocoaScreen

Generated Code

WSClient++ generates following sets of classes as below. So lets assume, following simple Inventory Web Service that allows us to Add/Delete/List products.

Synchronous Web Service Client

Synchronous Web Service Client class will be named as “NamedService”, which in our case will be “InventoryService”. Which will have synchronous methods which will make soap calls to destination server and will return the native representation of soap response in terms of custom types or native types as described by the WSDL. Synchronous client will wait for method call to finish, however it may return an error in case of timeout. But this may halt the user interface so we recommend using Asynchronous Web Service Client for most practical purposes.

Asynchronous Web Service Client

Asynchronous Web Service Client class will be named as “NamedServiceAsync” which in our case will be “InventoryServiceAsync”. It will have all methods same as that of Synchronous Web Service Client, but these methods will return nothing. Instead you will have to set a delegate which will have implementations of expected protocol, that will have actions for each method’s response and OnError.

Request/Response and Custom Types

For every custom xml type, WSClient++ will generate corresponding Objective-C class and it will marshal every request in xml as expected by Soap. You can simply invoke and access these objects as your other Objective-C classes, and NSWSDL.* files will do xml parsing and processing for you in background.

Invoking Web Service

After including generated files and NSWSDL.* (and NSXMLDocument.* for iOS)  in your project, you will be able to access web service in your project as shown below.

For Asynchronous calls, please define following methods which will implement responses of your web service and this class will be the delegate passed to web service.

Delegte Methods
  1. -(void) onError: (NSError*) error{
  2. //   … process error…
  3.  
  4. }
  5.  
  6. -(void) onCreateProduct:
  7.     (InventoryServiceAsync*)service
  8.     result:(Product*) r{   
  9. //… process result… you will get returned header here…
  10.  
  11. }

In the same class, we will call method to invoke the service as below,

Calling Web Service
  1. -(void) callService{
  2.     InventoryServiceAsync* ws = [InventoryServiceAsync service];
  3.     // set base url for entire application
  4.     [BaseWebService setGlobalBaseUrl: @""http://domain.com" ];
  5.     // //set base url only for this service
  6.     // [ws setBaseUrl: @"http://domain.com"];
  7.     [ws setDelegate: self]; // dont forget to set delegate
  8.     [ws CreateProduct: @”Sample”];
  9. }

So you see, calling Soap Web Service is very easy as you are calling your other native Objective-C API.

Download today your free trial at http://wsclient.neurospeech.com

Share
Tagged with:
 

WSClient++ Version 1.728 Released

On December 14, 2010, in News, by admin
1

We have updated WSClient++ (Version 1.728) that is available for download now. This edition addresses following issues,

  • Soap 1.1 Code generation is now supported.
  • Soap Headers are now supported for iOS, Android and Blackberry.
  • Date Parser has been fixed.
  • Dictionary type is now supported.
  • Array return types are fixed.

We will continue to upgrade WSClient++ to support various platforms as promised.

Click here to download Version 1.728.

Share
Tagged with:
 

Checkout the Screen Cast of WSClient++ for Java

WSClient++ is a code generation application designed by NeuroSpeech. It writes code for different platforms which can access Web Services from existing WSDL code. Given below is a step by step guide that will explain how to use this application to generate JAR libraries for Java platforms using WSClient++.

  1. Run Eclipse.
  2. Select and expand the project.
  3. Right-click the “src” folder.
  4. Expand the “New” option, and select “Package”.
  5. Enter the name of the new package and click “Finish”.

    This will create a new package within your Java project.

  6. Now run the installed WSClient++ application.
  7. Paste the WSDL Url in the “WSDL Urls:” field.

    WSClient++ will read your Web Service information from this WSDL Url and generate the necessary code.

  8. Make sure to select “Java” as your “Client Type”.
  9. Select the target as required.
  10. Specify the name of the package that was created earlier in step 5 in the “Package” field.
  11. Copy the path information of the package created in step 5 in the “Folder to store” field. This information can be obtained by right-clicking the package and selecting properties.
  12. Click “Generate” to generate the code.

    WSClient++ will now generate the Web Service code required for the application in Java to communicate with your Web Service for your application. This code will be provided in the .JAR file which needs to be added to your application’s Java Build Path.

  13. Now click the “Source and Library” button in the WSClient++ application. That will open a windows explorer window listing the WSClient.jar library.
  14. Copy the WSClient.jar library from this location.
  15. Open Eclipse, select the project, right-click, and paste the library into the project.
  16. Refresh the project.

    Now the library needs to be added to the Java Build Path for the project.

  17. Select and right-click the project.
  18. Select the “Properties” menu option.
  19. Select the “Java Build Path” option in the left menu.
  20. Select the “Libraries” tab.
  21. Click the “Add JARs” button.
  22. In the JAR selection window that appears, expand the project and select the WSClient.jar library that was copied and pasted earlier in steps 14 and 15.
  23. Click “OK” to close the JAR Selection window, and then click “OK” to close the “Properties” window.
  24. When the eclipse window appears, all the errors in the project should appear resolved.

    The WSClient++ settings for this particular project can be saved for use later as well.

  25. Open the WSClient++ window and click “Save Settings”.
  26. Provide the appropriate path information, provide a name for the settings, and click “Save”.
Share
Tagged with:
 

WSClient++ (Soap 1.2 Client Generator) Released

On July 14, 2010, in News, by admin
0

NeuroSpeech research and development team has finally perfected Soap 1.2 Client Generator for various platforms and it is live today for Cocoa, Java, Flash and .NET platforms.

Web Service Connectivity

Although SOAP is very popular among ASP.NET developers, most of implementations of SOAP is either incomplete or very time consuming and needs more knowledge of XML and SOAP. Today we are building applications on variety of mobile platforms, that requires Web Service connectivity to servers to pull data and to perform business transactions. And today mobile platforms have become more powerful and that has given opportunity for us to deploy enterprise applications on mobile platforms. Today ASP.NET Web Services are very common way to communicate between enterprises and to develop service oriented applications. So there was a great need for powerful SOAP tools, and we identified that platforms like iPhone (iOS), Mac OSX, Android, Blackberry, Flash have very limited options for enterprise web service connectivity.

WSClient++ Program

WSClient++ program lets you define configurations of your enterprise connectivity and it generates source code that can be used without any knowledge of XML/SOAP. All you have to do is, configure your connectivity, i.e. specify the WSDL url, specify folder and files to be generated and hit the Generate button.

It is available for Mac OSX 10.5+ and for Windows XP SP2 onwards. This program is written in Adobe AIR, so that it is available on multiple platforms.

Key Highlights

  1. Objective-C source code generator, fully optimized for memory, asynchronous and synchronous client generator
  2. Java source code generator, full optimized for memory, fully implemented Parcelable interface for android
  3. Ability to generate source code of multiple web services in single namespace/package sharing single inheritance hierarchy
  4. Source code generated is formatted according to native platform requirements
  5. Additional libraries for XML/SOAP connectivity is included with source code

Known Limitations

As we are trying to provide facility for light platforms (mobile/flash) to connect to ASP.NET enterprise web services, every data type of ASP.NET is not supported yet. We do support multiple classes and class hierarchy but things like byte[] etc are not yet implemented, we support members of class should be only of type “Class” and “int, long, float, double, DateTime, bool and String” and arrays of supported types. As new versions will be available in future, we are working towards including byte[] and add more types to the program and we are working on implementing Soap with Attachments in near future soon.

Download Demo Edition

Demo edition has following limitations.

  • 10 Seconds wait before Starting Application
  • Only generates first two methods of Web Service
  • Only generates first two web services from the list of WSDL urls passed
  • No Asynchronous Clients for Cocoa and Java
  • No Parcelable Implementation for Android
  • Click Here to download and install Adobe Air 2.0.
  • Click Here to download and install WSClient++ 1.22.

  • Share
    Tagged with: