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!
Linux from Scratch
January 12th, 2006
hi!!, came across this site called Linux from Scratch, that teaches you to build your own, customised linux from the source code. The site is very interesting and would be very useful for adventerous guys (he he).
Also check the linux documentation project. The site has also documented the linux kernel.
LINQ Framework
December 22nd, 2005
LINQ or Language INtegrated Query is a set of classes in .NET that allows you to query arrays just as would query a database, using keywords such as ‘select’, ‘where’ etc.
Sounds interesting?? I’m just exploring it. Have a look at these sites in that order.
1. http://blogs.msdn.com/danielfe/archive/2005/09/13/464904.aspx
2. http://blogs.msdn.com/sriram/archive/2005/09/16/468927.aspx
There is also a video at channel9…Do check it out…http://channel9.msdn.com/showpost.aspx?postid=114680 and here is the related MSDN link that offers a lot of code samples and downloads.
By the way, it is supposed to be shipped with the next version of Visual Studio (Orcas).
Insecure SMTP…
December 5th, 2005
hi!!
You may be knowing about SMTP. Its called Simple Mail Transfer Protocol. SMTP is responsible for transfering mails from 1 server to another server. Suppose you want to send a mail from yahoo mail to gmail, the yahoo server sends the mail to the google server through SMTP. To know in detail about the SMTP sepcification, refer RFC 2821 at ietf.org.
Coming back, when a mail is about to be sent, a domain called the “Mail Exchanger (MX)” is contacted, which relays the mail to the destination. The mail exchanger works on default smtp port (25). This MX can be contacted directly by bypassing the usual web interface (that we are used to) and thus anonymous mails can be sent!!! Sounds dangerous?? Read on….
For example, lets take a fictitious website called http://www.abcdefghij.com/ and lets assume its having a MX. In linux OS, we use the dig (i don’t know the windows equivalent) command to retrieve the MX record of a website. On issuing the command at the terminal,
dig abcdefghij.com mx
a list of url’s popup as the result. Look for “;; ANSWER SECTION“. At the end of the line, there will be a url which is the mail exchanger. Ofcourse, a website may have many MX records.
Now, we have to connect using telnet to port 25, the standard SMTP port at any of the MXs.
telnet mx1.abcdefghij.com 25
Your output should look similar to
Connected to mx1.abcdefghij.com
Escape character is ‘^]’.
220
For each line of command you type, you will get a response. Normally, an email will have a from address, to address, subject, content. Issue the next command as follows.
MAIL FROM:<xyz@abcdefghij.com>
503 // Server output
RCPT TO:<abc@abcdefghij.com>
503
DATA
503
Subject: this is subject // A blank line is a must after this line
this is the content
. // ‘.’ (dot) signifies content end
QUIT
221 mx1.abcdefghij.com
Connection closed by foreign host
Your mail will be sent now. Almost no servers will support foreign relaying. That is, if u want to use the MX of yahoo the ‘MAIL FROM’ should have its email address ending in yahoo.com or something that the yahoo servers support. The ‘RCPT TO’ can be any valid email address. Have a look at this url http://www.yuki-onna.co.uk/email/smtp.html for having a detailed explanation on sending mails using SMTP & terminal
Why this is insecure??
It allows emails to be sent without logging in. Only the domain of FROM address is checked to see whether its legal for relaying. That too, the email address is not verified. Therefore, unscrupulous spamming is a possibility. Connecting on normal SMTP offers a bit of security because, the email address is verified for its existence.
Hope this helped a bit…..bye!!~~
AJAX
November 28th, 2005
hi!!
AJAX or Asynchronous Javascript & XML seems to be the coolest or hottest (in whichever way u want) technology around. It deals with sending asynchronous requests to the server behind the scenes, and its a very good way of showing interactive content.
It comes with lot of advantages. One of them being; large data driven websites need not refresh whole pages of data always to display new content. Gmail is 1 of the many sites that uses AJAX heavily.
In .net, AJAX is implemented as “Atlas” and in J2EE, any app server that supports servlets will support AJAX.
To know more about it, follow the wikipedia link. Check out the Atlas link to know more about it in .net. As for J2EE, read this excellent article on implementing AJAX. As usual, there are some FAQs as well and some common pitfalls that you should avoid.
Happy coding bye!!~~