WCF service is implemented and debugged in Windows Azure
Source: Internet
Author: User
KeywordsWindows AZUREWCF
Windows Communication Foundation (WCF) is a widely used client/server-side communication technology, provided by Microsoft and is now highly skilled. It broke the original a dialog can only interact with one, and WCF services can communicate with a WCF client, as well as with clients from other frameworks that use the same standards. This is very rare. To expose services running in Windows Azure that use a powerful WCF framework, Windows Azure is not outdone, providing a WCF role for the platform. Regardless of the framework and platform on which builds complex, highly scalable systems, you can make things simpler and more efficient by simply grouping them logically through the features of Windows Azure and by performing them separately for those groups that abstract code.
This article focuses on the basics of creating and using WCF roles in Windows Azure, and how to diagnose errors that occur within a WCF service. In addition, this article will provide you with some known issues and basic solutions to the problems that you will encounter when you log Windows Azure's WCF trace information to a journal. In addition, we will provide the relevant source code.
First, we must create a new Windows Azure project that uses the Windows Azure SDK v1.3, and then add a new WCF role to it. This role is created by Visual Studio and comes with a number of useful underlying settings and services. It's worth noting that creating a WCF service is not the only way to do it, you can also use the web role or worker role (even a VM role!). )。 However, if we create a service that uses the WCF role template, things will get easier. Also, this should draw our attention to the fact that there is no essential difference between using a WCF role and using a web role, and if you are using a worker role, the situation is different. The difference is that both the WCF role and the Web role are hosting WCF services in IIS, and when you use the worker role, you can only be hosted in a Windows application. This specific information, you can refer to: http://msdn.microsoft.com/en-us/library/ms730158.aspx.
Let's go back to the task at hand and create a WCF Service Web role for our project:
This creates a Web application (similar to a web role) and also adds some basic code files.
These are the basic components of a very basic WCF service, and now let me elaborate on what they do. If you are a veteran of WCF, you can skip this section!
AzureLocalStorageTraceListener.cs:
This is a derived class of "XmlWriterTraceListener", and the main function of the "XmlWriterTraceListener" class is to collect log information written by the "System.Diagnostics.Trace" class. They are then exported in the form of XML. This is a "xmlwritertracelistener" for a specific purpose-it always writes xml-based trace information to an area of localstorage. Windows Azure allows a role to write to a writable region of the disk. You can write a file path in this particular way so that the Windows Azure Diagnostics Framework knows where to choose files from. The Windows Azure Diagnostics framework must move them to a local instance of a role instance so that they can be used across instances.
IService1.cs:
This file contains an interface and a class. They are all interesting because their definitions are decorated with attributes. The interfaces in "IService1.cs" are decorated with attributes [ServiceContract]-meaning that in this application, this interface defines a service contract. It can be used for WCF, which means that both the client and the server agree that certain methods can be used on this service, internally, that these methods are decorated with operationcontract. Classes in IService1.cs are decorated with attributes [DataContract], whose members are decorated with attributes [DataMember]-This provides a way to specify the details of the message that both the client and the server agree on that can be passed between the client and server.
Service1.svc (and Service1.svc.cs after it is expanded):
This class implements the above interface declared with "IService1", which means that when you connect to a WCF service that uses the IService1 implemented by "Service1.svc", these are the real logic to be executed. Note that in this example, the path to "Service1.svc" always provides such functionality, but in an advanced WCF configuration you can replace the. svc with a configuration that allows for greater flexibility.
Web.config:
This is the configuration file for the Web application. Notably, by default, "Azurelocalstoragetracelistener" is disabled, and the "System.ServiceModel" node defines that we can use "http" (a base Web request) to obtain the metadata for the service. This setting is useful because we can use a browser to browse the service during the development process.
WebRole.cs:
This is a derived class of "roleentrypoint" that controls how the WCF role starts in Windows Azure. The "OnStart" method is used to configure how Windows Azure Diagnostics information is migrated to BLOB storage, which is done one time per minute by the path configured in "Azurelocalstoragetracelistener." Note that local storage should be defined like this:
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.