domingo, 27 de maio de 2012

Creating a ASP.NET Web Service (C#) in Visual Studio 2010

Creating the Web Service

  1. Go to the File menu, New and click New Web Site. 
  2. In the text box where is defined the location (ex: http://localhost/WebSite ), change "WebSite" to the name that you want for the Web Service. I'm going to use, PoolService, so, "http://localhost/PoolSerives".
  3. Select Visual C# in the installed templates, and proceed to select ASP.NET Web Service. Click OK

Now if you have IIS working and you press CTRL + F5, something like this should appear. HelloWorld is a method from your, just created, web service.

Now to add some more methods...   



Adding Methods to the Web Service

What we have now is a web service called "Service". Let's add another web service.
  1. In Solution Explorer, right-click the Web site name (http://localhost/PoolServices), and then click Add New Item.
  2. Under the Visual C# Installed Templates, select Web Service, and change the name. I'm going to use the name Calc.asmx
  3. Make sure you don't forget to check the box Place code in separate file, and click Add.
  4. Now open the Calc.cs file and add this code inside the Class Calc, for exemple after the HelloWorld method:
  5. Now if you press CTRL + F5 again you should see the "Add" method next to the "helloworld" method. If you click it, you should see two text boxes. This text boxes represent the two variables that we require for the "add" method, and if you invoke the method after typing the numbers, a xml file will appear with the result.
  6. You can add more methods, for example, add a method to subtract the numbers. just below the add method (don't forget that every method requires writing [WebMethod] before his definition).

Adding a Web Service to another Project

Now the cool part. Now that we have a web service with one method (or more), we can use it in another projects giving real use to the Web Service. Go to the File menu, New and click New Web Site. 
  1. Go to the File menu, New and click "Project..." 
  2. On C# installed Templates, select Windows Forms Application, give it a name and click OK.
  3. With the Design layout add 2 textbox, 1 button and a label (you can find them in the Toolbox). 
  4. With the help of the Properties window change the name of the button to "addBtn".
  5. Now, go to the Solution Explorer, right-click the name of the project, and then click "Add Service Reference...".
  6. In the address textbox insert the path to your webservice. For exemple: "http://localhost/PoolServices/Calc.asmx" click Go to test it, and it should appear your service in the "Services:" zone. by expanding the service found, you can see his methods on the "Operations:" zone. Define the namespace for the Service (ServiceCalc for example) and click OK.
  7. To add the code in the form double click on the button that was just created with the name "addBtn". Add this code to the addBtn_Click method: 
  8. CTRL + F5 and it should work :)

domingo, 20 de maio de 2012

How To Install Java 7 In Ubuntu 12.04


Because we are using old software in my school, my professor advised not to install java 7 and instead we should use java 6. However, im going to use java 7 for two reasons:

  • Im going to use java for developing android apps.
  • Java 6 is reaching its end of life;
  • And Oracle has decided to nullify any license allowing distros to maintain Java in their repos;
So, the easiest way i found to install java 7:


  1. Add this PPA's:


  2. Install and enter the config:


  3. And set witch jvm will you use:
Kudos to webupd8 and Eugene San

Confirm that java is installed by typing "java -version" and "javac -version"

Now... like me, you may want to define your $JAVA_HOME and $PATH variables

By default your java should be in "/usr/lib/jvm/java-7-oracle" (if not, don't worry, use your directory).
Open your terminal and type "sudo nano /etc/bash.bashrc"* (im using "nano" but you can use "gedit" or other editor).
Add this lines to the end of the file:
"export JAVA_HOME=/usr/lib/jvm/java-7-oracle"
"export PATH=$PATH:$JAVA_HOME/bin"

Save it and close it. To confirm that everything is working, log out and log in again, open a terminal and type: "echo $JAVA_HOME". The output should be something like "/usr/lib/jvm/java-7-oracle".


*if the variable is not set try using the file "~/.bashrc" instead of  "/etc/bash.bashrc"

quarta-feira, 16 de maio de 2012

Just a netbook

This is simply a way to keep track of all the things that i learn from school, the "internets" and the wilds.