Consuming a Java Webservice in .Net
February 24th, 2006
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!
July 17th, 2008 at 9:00 am
[…] 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 […]
April 11th, 2009 at 10:42 pm
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
April 16th, 2009 at 7:15 pm
Hei it’s working fine in ASP.NET.
Very nice one….
April 22nd, 2009 at 11:30 am
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
May 14th, 2009 at 5:46 pm
@mani
Can u pls give me the reference or the sample code for asp.net
August 19th, 2009 at 11:02 am
Hi,
I want to know where should i have to change for redirecting to my home page.
November 4th, 2009 at 4:58 pm
Hey can any one provide me the code for ASP.Net Application.
Thanks and Regards,
G.V.N.Sandeep
December 19th, 2009 at 4:25 pm
I am unable to do.Please help me..
December 23rd, 2009 at 10:34 am
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
December 24th, 2009 at 6:42 pm
Hello aswin !!!
PHP API not working properly it shows Invalid Login Message.
Sanjeev.
December 24th, 2009 at 6:43 pm
please provide new API for send fre SMS dear 🙂
January 4th, 2010 at 11:43 am
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.
January 6th, 2010 at 11:58 am
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.
January 7th, 2010 at 3:14 pm
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
January 14th, 2010 at 11:40 am
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.
January 21st, 2010 at 2:16 am
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
January 21st, 2010 at 2:19 am
I have use in Dotnet code Some error was accrued
June 1st, 2010 at 5:40 pm
hi
Ashwin i m using ur wsdl http://www.aswinanand.com/sendsms.php?wsdl but this is not working for me
June 10th, 2010 at 3:47 pm
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.
June 10th, 2010 at 3:52 pm
hii i m getting invalid login for the 1st method though my userid n password of way2sms are valid
July 2nd, 2010 at 4:53 pm
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”);
March 14th, 2012 at 6:48 pm
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
June 14th, 2013 at 11:03 am
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.