WCF host validation queue and wcf host queue
ServiceHost host = new ServiceHost(typeof(Service1)); if (MessageQueue.Exists(@".\private\MyMessageQueue") == false) { MessageQueue.Create(@".\private\MyMessageQueue", true); }
host.Open();
In the above example, the host checks whether the MSMQ queue has been created before opening it. If you need to wear a part, the host code can complete this work. Note that you can set the transaction queue using "true ".
Why is the wcf Service managed? What is the role of the host environment?
The answer from the Microsoft forum is as follows:
1. WebService: strictly speaking, it is an industry standard, not a technology. XML extension markup language is used to represent data (this is the key to boast of languages and platforms ). Microsoft's Web Service implementation is called ASP. NET Web Service. It uses the Simple Object Access Protocol Soap to implement data interaction between applications in a distributed environment. Description of the service interface. In addition, Web services can be registered to the UDDI Center for customers to find and use.
Later, Microsoft implemented ASP. NET Web Service Security, performance, data encryption, decryption, hosting host and other aspects of the extension, called the WSE series, this is an over-product, up to WSE3.0. later is the WCF era.
2. WCF: to some extent, it is ASP. NET Web Service, because it supports the industry standard and Core Protocol of Web Service, ASP. NET Web Service and WSE can do almost all the things they can do. cross-platform and language are not a problem (data also supports XML formatting and provides their own formatter ).
However, as a communication component or platform promoted by Microsoft, WCF aims not only to support and integrate Web Services, because it is also compatible with and has many features of Microsoft's early technology.
According to Microsoft's official explanation, WCF (formerly called "Indigo") is a unified framework for building and running Service-Oriented applications using managed code. It enables developers to build a secure, trusted, and transactional solution across platforms, and to be compatible with existing systems. WCF is a set of developers for Microsoft Distributed Application Development. It integrates. net platform, such as Enterprise Sevices (COM + ). net Remoting, Web Service (ASMX), WSE3.0, and MSMQ message queues. In terms of the scope of communication (Communiation), it can be cross-process, cross-machine, cross-subnet, enterprise network, or Internet; in terms of host programs, it can be ASP. NET, EXE, WPF, Windows Forms, NT Service, COM + as the Host (Host ). The protocols supported by WCF include TCP, HTTP, cross-process, and custom. Security modes include SAML, Kerberos, X509, user/password, and custom. That is to say, it is easy to develop a SOA-based Distributed System under the WCF framework. Microsoft includes all the technical elements related to this, and has mastered the concept, it is equivalent to mastering the key to open the SOA door.
How does the WCF Service interact with the Host Program?
Here is an example: the WCF WAFService inherits from IWAFService and has only one Operation: void DisplayContent (string content). The host of this service is in a WinForm program, when the client accesses DisplayContent, the content of the parameter will be displayed in the WinForm List control LBContent. There are two key points here: first, you need to perform more control over the WCF Service. Therefore, you need to use the construction function ServiceHost (Object, Uri () instead of the usual ServiceHost (Type, uri (). The former directly transmits the WCF Service instance to the ServiceHost object. Therefore, the instance management of the WCF Service must be Single (InstanceContextMode = InstanceContextMode. single, while the latter transmits only the type of the WCF Service. ServiceHost determines how to create and destroy the WCF Service instance at an appropriate time. Second, in the class definition of the WCF Service, you need to add a Public delegate. When the Operation of the WCF Service is called, it is used to call back the methods in the Host Program. The main code of this instance program is as follows: [csharp] view plaincopy? Namespace WFAWCF {public delegate void DisplayContent (string content); [ServiceBehavior (InstanceContextMode = InstanceContextMode. single)] public class WAFService: IWAFService {public DisplayContent AddContent = null; public void DealWithContent (string content) {if (! String. IsNullOrEmpty (content) {if (null! = AddContent) AddContent (content); Console. WriteLine (content) ;}}} WCF Service Program
For less important interface definitions and configuration programs, skip this section.