다음을 통해 공유


Creating a Web Service in Cloud

Let's create our first web service in the cloud. The service will return the factorial of a number. Just like our Hello World ASP.NET application, we will create a new Cloud Service project but this time with no Role. Once the project is created, add a new ASP.NET Web Service Application project to the solution and add it as a Web Role in the Cloud Service project. In the web service, just add the following methods.

 

 

 

 

Now, press F5 and you will get the following.

 

 

 

 

Don't close the existing solution. Copy the URL address and open a new Visual Studio environment with a new solution and a Console project. Add a service reference to it, providing the above URL.

 

 

 

 

FactorialReference is the namespace given to this web service reference. Use it to calculate the factorial and output the result. Press F5 and you will see the command window output "The factorial of 5 is 120".

 

 

 

 

Why did we do that, you will know in the end. Now, stop both the solutions and publish the web service just the way mentioned in the Windows Azure: Hello World Part 2.

 

Once you have successfully deployed and run the web service, it is time to update the reference of the console application. Open the "app.config" of the console project and modify the client endpoint address to set to the production URL of the web service in cloud.

 

 

 

We did not directly update the service reference in the console project to point to cloud directly because that does not work. This is because of some configuration of internal Windows Azure environment to handle internal and external comms pathways that needs to be fixed. But since we have a workaround, we don’t need to worry about that.