How to use the WCF Service Web role

Source: Internet
Author: User
Keywords AZURE WCF Service Web Role

In this article we create a WCF service role primarily on local development fabric and use it in a console application.

Windows Azure is a Silverlight based software, and its development portal is now a new one. All of its information, all operations can be done in one page. Use this new portal, from configuring the guest operating system to stopping or restarting a service, almost on one page, to get everything done. in this article, we'll create a WCF service role, host it on the local development fabric, and then use it in a console application. the WCF service role allows us to create a WCF service and host it in Windows Azure. Next, let's see how to create a WCF service.

First of all

1, create a new project

2, navigate to the "Cloud" tab

3, create Windows Azure Project

4, select the WCF service role in the given option

If you look at Solution Explorer, you will find that the structure and files of this WCF service role project are exactly the same as the WCF Service application that is normally created. It contains:

1,iservice1.cs (service contract)

2,service1.svc.cs (service definition)

3,web.config (Endpoint configuration)

We can modify these files according to our requirements, which is no different from what we do in a WCF service application.

Let's modify the service contract:

Iservice1.svc

Using System.ServiceModel;

Namespace WCFServiceWebRole1

{

[ServiceContract]

public interface IService1

{

[OperationContract]

string GetData (int value);

}

}

Then, modify the service definition:

Service1.svc.cs

Namespace WCFServiceWebRole1

{

public class Service1:iservice1

{

public string GetData (int value)

{

return string. Format ("you entered: {0}", value);

}

}

}

Leave the default configuration in Web.config.

Make sure you've set up the Windows Azure Project to start the project, and then run the application. In the browser, you get the following error message:

Ignore this error message and add a URL to "Service1.svc", which should be http://127.0.0.1:81/Service1.svc. "Service1.svc" is the name of the service definition. After adding, you will get the usual WCF service message in the browser

To test this WCF service role in a console client, you need to:

1, create a console Application project

2, add a service reference using the specified URL (http://127.0.0.1:81/Service1.svc)

Now we write a normal service call:

Program.cs

Using System;

Using System.Collections.Generic;

Using System.Linq;

Using System.Text;

Using Consoleapplication14.servicereference1;

Namespace ConsoleApplication14

{

Class Program

{

static void Main (string] args)

{

Service1client proxy = new Service1client ();

var result = Proxy. GetData (99);

Console.WriteLine (result);

Console.readkey (TRUE);

}

}

}

Now, when you run this application, you may get the following exception:

To resolve the above exception, we must edit the "app.config" file. We need to modify this configuration file:

"127.0.0.1" stands for "localhost". Perhaps this console application cannot parse "127.0.0.1", so we change it to "localhost":

Now, to run this application, we'll get the following output:

One of the behaviors we need to be aware of here is that sometimes, after you change "127.0.0.1" to "localhost," you may still get that timeout exception. In my future article, I'll delve into this unexpected behavior.

Original name: Windows Azure for Developers Task 8:working with WCF Service Web role Author: Dhananjay Kumar

"This article is 51CTO selected translations, reproduced please indicate the source!" 】

"Edit Recommendation"

Microsoft announces cloud computing Platform Azure toll model details Cloud computing is meant to be long term, Microsoft Cloud Computing Services Windows Azure has enabled technical dialysis: Windows Azure Platform Framework with Microsoft Windows Azure Platform Technology Analytics Approaching Microsoft Cloud: SQL Server to Azure data synchronization when Microsoft Azure encounters Amazon EC2: five key differences Windows Azure cloud computing platform adds five features cloud future bright azure users break 31000 How to deploy an application to Windows In Azure

"Responsible editor: Wang Yong TEL: (010) 68476606"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.