hi!! guys, yesterday i developed a simple “Hello World!” webservice with java. With Netbeans 5.0 IDE its a breeze to create web services. It comes bundled with Apache Tomcat 5.5.9 and Sun Java Application Server 8.2.

You can find the quickstart tutorial here to develop web services. Just follow that tute and you will be fine. I will tell you how to consume the same using .net. I used Visual Studio 2005 to consume this service. I assume that you have the url for the wsdl of the webservice which should be similar to, http://localhost:8080/WebApplication1/NewWebService?WSDL.

1. Open Visual studio. “File->New->Website”. If using VS2003 then, “File->New->Project->ASP.NET Web Application”.
2. A web application should have been created by now and you have the “design view” of “default.aspx” or any other aspx page of your choice.
3. Press Ctrl+Alt+L or View->Solution Explorer. Right click on your project name and select “Add Web Reference”. In the windows that pops up, give the WSDL url and an “Instance Name”. My instance name was “JavaAdd”.
4. Add a button and a label to the asp.net page. Double click the button and paste the following code.

VB.NET
Dim js As New JavaAdd.NewWebService()
Dim myadd As New JavaAdd.add()
Dim myaddRes As New JavaAdd.addResponse()
myadd.int_1 = 10
myadd.int_2 = 10
myaddRes = js.add(myadd)
Label1.Text = myaddRes.result

C#

JavaAdd.NewWebService js = new JavaAdd.NewWebService();
JavaAdd.add myadd = new JavaAdd.add();
JavaAdd.addResponse myaddRes=new JavaAdd.addResponse(); myadd.int_1=10;
myadd.int_2=10;
myaddRes=js.add(myadd); Label1.Text=Convert.ToString(myaddRes.result);

Instead of “sayHi” method in the quickstart tute, i created a method called “add” which accepts 2 integer parameters and returns an integer after adding them up.

5. Press F5 now. You should get something similar to these.

Thats it for this post…bye!

23 Responses to “Consuming a Java Webservice in .Net”

  1. Waves » Blog Archive » Send Free SMS - Web Service Says:

    […] More details on how to consume a web service using Visual Studio is available here. Feel free to try with other languages and IDEs and let me […]

  2. Prashanth Says:

    Hello,
    I am trying to implement the same in Asp.net but unable to do.
    Steps I did
    1. Adding web ref
    http://www.aswinanand.com/sendsms.php?wsdl
    Name instance : “JavaAdd”
    2. As suggested added button and in click event wrote
    “JavaAdd.NewWebService js = new JavaAdd.NewWebService();
    JavaAdd.add myadd = new JavaAdd.add();
    JavaAdd.addResponse myaddRes=new JavaAdd.addResponse(); myadd.int_1=10;
    myadd.int_2=10;
    myaddRes=js.add(myadd); Label1.Text=Convert.ToString(myaddRes.result);”

    3. Getting this error.
    “Error 7 The type or namespace name ‘NewWebService’ does not exist in the namespace ‘JavaAdd’ (are you missing an assembly reference?) c:\inetpub\wwwroot\SMS\Default.aspx.cs 20 17 http://localhost/SMS/

    I have added the namespace of it too. ..

    Please guide.

    Thanks and Regards,
    Prashanth Kuamar Ganathe

  3. Mani Says:

    Hei it’s working fine in ASP.NET.
    Very nice one….

  4. Prashanth Says:

    Will you plz give the url of webservice and code for it.
    I am getting this message

    “Sends the same SMS to multiple phone numbers. Give your 10 digit phone number for user ID. Separate each phone number with a semicolon(‘;’).”
    for this link
    http://www.aswinanand.com/sendsms.php?wsdl

    Thanks

  5. Fahad Pathan Says:

    @mani
    Can u pls give me the reference or the sample code for asp.net

  6. Rajeevgandhi Says:

    Hi,

    I want to know where should i have to change for redirecting to my home page.

  7. Sandeep Says:

    Hey can any one provide me the code for ASP.Net Application.

    Thanks and Regards,

    G.V.N.Sandeep

  8. BHAVNISH Says:

    I am unable to do.Please help me..

  9. Rahul Says:

    Respected Ashwin,
    Iam using your great service for asp.net project but as iam using your webservice http://www.aswinanand.com/sendsms.php?wsdl
    with instance name JavaAdd
    there is nothing JavaAdd.NewWebService
    So what can i do please help sir, kindly reply ASAP

  10. sanjeev Says:

    Hello aswin !!!

    PHP API not working properly it shows Invalid Login Message.

    Sanjeev.

  11. sanjeev Says:

    please provide new API for send fre SMS dear 🙂

  12. hemal Says:

    hi,I have tried your webservice in asp.net but it still provides the error such as “try after sometime port is busy.” I tried also the url provided in your website and provide my way2sms valid id and password but it still provide the message “invalid login”.

    So, please reply. this webservice actually works or not?
    is this a fake webservice? because i tried a lot to use it.

    so please reply.

  13. ashish Says:

    i tried ur webservice in c#. My code was

    com.aswinanand.www.SendSMS sendsms = new com.aswinanand.www.SendSMS();
    string str = sendsms.sendSMSToMany
    (“my number”, “password”, “receiver number”, “hi”);
    it gives invalid login…but my login Id and pwd is right because i can directly send sms using same id and pwd from way2sms website. any help will be appreciated? pls reply asap.

  14. thyagarajan Says:

    i tried ur webservice in vb.net My code was

    Dim js As New JavaAdd.SendSMS
    js.sendSMSToMany(“mynumber”, “pwd”, “receiverno”, “testmessage”)

    no error msg but message not received pls reply me

  15. Anon Says:

    Hi, Even I am getting this error, that invlaid login, even though login is valid and I am able to login into way2 sms. I using ur web service.

  16. Bhuvaneswaran Says:

    http://www.nediyosoft.com/sendsms.php

    error message
    invalid_request Usage: Refer to http://www.aswinanand.com/blog/2008/07/send-free-sms-web-service/ for more informaiton.

    pls Help Me

  17. Bhuvaneswaran Says:

    I have use in Dotnet code Some error was accrued

  18. Sajid Says:

    hi
    Ashwin i m using ur wsdl http://www.aswinanand.com/sendsms.php?wsdl but this is not working for me

  19. rdp Says:

    Hello,
    I am trying to implement the same in Asp.net but unable to do.
    Steps I did
    1. Adding web ref
    ” http://www.aswinanand.com/sendsms.php?wsdl”
    Name instance : “JavaAdd”
    2. As suggested added button and in click event wrote
    “JavaAdd.NewWebService js = new JavaAdd.NewWebService();
    JavaAdd.add myadd = new JavaAdd.add();
    JavaAdd.addResponse myaddRes=new JavaAdd.addResponse(); myadd.int_1=10;
    myadd.int_2=10;
    myaddRes=js.add(myadd); Label1.Text=Convert.ToString(myaddRes.result);”

    3. Getting this error.
    “Error 7 The type or namespace name ‘NewWebService’ does not exist in the namespace ‘JavaAdd’ (are you missing an assembly reference?) c:\inetpub\wwwroot\SMS\Default.aspx.cs 20 17 http://localhost/SMS/”

    I have added the namespace of it too. ..

    Please guide.

  20. preethi Says:

    hii i m getting invalid login for the 1st method though my userid n password of way2sms are valid

  21. sanjeev Says:

    heloo sir i m using this code bt this is not working
    output are nothing
    com.aswinanand.www.SendSMS sendsms = new com.aswinanand.www.SendSMS();
    string str = sendsms.sendSMSToMany
    (“98*******”,”pwd”, “98*******”, “hi”);

  22. rohini Says:

    hi i am student of MCM and i am doing project in asp.net and i want to send the appointment to the client via sms so plz tell me how can i do this,i have a way 2 sms account also plz send me mail

  23. shananu Says:

    kindly send me compete code & instructions of sending free sms on asp.net 4.0 version using c#
    please make sure its updated version as per way2sms.
    txs in advance
    i need it asap.