Azure Services Discovery-adding WCF services to Azure service

Source: Internet
Author: User
Keywords Then HTTP you can
Tags address change click client code configuration create error
This article is going to explore from the Azure service--the localstorage that the article inspires, because in file system storage we talk about Localstorage, and then to learn about the use of worker role, The idea is to create a temporary file system in Web role first, and then provide a WCF service to the Web role, which the worker role calls to share and write to the temporary file system.

In fact, the transformation is to solve how to provide a WCF service in Azure Service, and then how this WCF is configured and invoked by other roles (Worker role, other Web Part) or another Azure service.

Basic interface design as follows, alas not creative, or use the previous example to modify

The Web role interface of the foreground does not change or writes a message to a localstorage, but it also provides a WCF service and can write messages to this localstorage, while the worker role in the background invokes the WCF service on a regular basis. Writes ping information.

Once the process is determined, you are ready to start the operation.

First, create a Web role + Worker-Role Project

Next, define the file store in the service definition file, and then copy the code before the Web role. F5 run, no problem, and then we start adding WCF services

Click on the Web Role item and choose Add a new option (Add New Item), as shown in

Then define a WCF ServiceContract

1:namespace Hostingwcfservices_webrole
2:
3: {
4:
5: [ServiceContract]
6:
7:public Interface Imessagelogger
8:
9: {
10:
One: [OperationContract]
12:
13:void logmessage (String message);
14:
15:}
16:
17:}
18:

Then implement this interface in the MyMessageLogger.svc.cs, the concrete implementation is very simple, is writes the message to the file store.

After that we need to check and confirm the WCF configuration file and make a change to change the Wshttpbinding to BasicHttpBinding, as shown in the following figure:

For BasicHttpBinding and Wshttpbinding differences, see the last link in the article. In addition to performance, support for WS protocol support, session/transactions, and so on, the security Mode and the Client credential Type in WCF article give good advice: If broad reach across Platforms is your goal, there's no decoupled choice today than using the WS-I Basic profile over SSL abound of marshalling would also score us ing BasicHttpBinding instead of wshttpbinding. It ' s important to the particular binding doesn't ' t provide CIA by default.

You can then F5 start our Azure service and then visit WCF's address http://localhost/myMessageLogger.svc to test whether the WCF service works correctly.

Then I have the following error page in my development environment:

Some interesting phenomena can be found from this interface, first, Azure uses another port 127.0.0.1:5100, and second, it is proved that BasicHttpBinding does not have a security label with the default.

See the left detail Error information feel. svc file seems to have no process to handler, feel IIS7 with a static file process in processing, thinking for two minutes, the mind flashed was, then go to Control Panel check, found that was ( Windows Process activation Service) is not installed.

Then quit visual Studio to install the system, I was running on Windows Server 2008, and the interface to install was is as follows:

After installation, you do not have to reboot, continue F5 run, the WCF service can access the

According to the previous design, the current task is half done, and we have successfully published a WCF service that records messages in a Web role, and the rest is to invoke this WCF service in the worker role.

Now you can click on the Worker role item and choose Add Service Reference (add Services Reference)

Here's a little tip, because the WCF service isn't running when you're developing a debugging environment, you can enter HTTP://LOCALHOST/MYMESSAGELOGGER.SVC in the Address box and click the Discover button, and then the port number in the Address box changes automatically. , when the native asp.net Web Development server started the new port number that was generated, we are just adding a reference, 1030 port is not azure running WCF port, if there is a port that we just saw on the error page 5100. After adding the WCF service reference, remember to modify the app.config configuration file for the worker role, remove the port number of the address in the <endpoint address>, and maintain the HTTP://LOCALHOST/MYMESSAGELOGGER.SVC configuration.

You can then write code for the worker role to add messages to the Web role's File store via WCF Proxy.

1:public override void Start ()
2:
3: {
4:
5://This is a sample worker implementation. Replace with your logic.  
6:
7:rolemanager.writetolog ("Information", "Worker Process entry point called");
8:
9:string wcf_url = "Http://localhost/myMessageLogger.svc";
:
11:while (True)
:
: {
: 15:thread.sleep (10000); 
:
17:basichttpbinding bind = new BasicHttpBinding ();
:
19:endpointaddress endpoint = new EndpointAddress (Wcf_url);
:
21:hostingwcfservices.messageloggerclient client = new Hostingwcfservices_ WorkerRole.HostingWCFServices.MessageLoggerClient (BIND, endpoint);
:
23:client. LogMessage ("Ping from Workerrole"); 
:
25:rolemanager.writetolog ("Information", "Ping from WORKERROLE-WCF messageloggerclient");
:
27: if (client. state = = communicationstate.faulted
:
29:client. Abort ();
:
31:else
:
33:client. Close ();
:

:
:}
:

The code for the background worker role is also completed, and then F5 runs. The running interface is as follows:

By hosting WCF services in the Web role lets us find another way to share azure capabilities or services, shared and exposed WCF can be used by other roles in Azure services, and can be provided to applications and clients outside the cloud , which is a powerful tool and a way for the Windows Azure platform to provide an application portfolio.

In another final experience, we also tried to invoke and consume this WCF service using the worker role, which also points us to another way of applying consolidation, and our azure services itself can consume from other windows Services and capabilities on Azure platforms or on the Internet. The Webrole of Azure services and the architecture of the worker role also give a glimpse of the features and beauty of cloud applications.

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.