赛派号

生物技术专业排名榜 Self

The SelfHost sample demonstrates how to implement a self-hosted service in a console application. This sample is based on the Getting Started. The service configuration file has been renamed from Web.config to App.config and modified to configure a base address, which the host uses. The service source code has been modified to implement a static Main function that creates and opens a service host that provides the configured base address. The service implementation has been modified to write output to the console for each operation. The client has been unmodified, except for configuring the correct endpoint address of the service.

Note

The setup procedure and build instructions for this sample are located at the end of this topic.

The sample implements a static main function to create a ServiceHost for the given CalculatorService type, as shown in the following sample code.

// Host the service within this EXE console application. public static void Main() { // Create a ServiceHost for the CalculatorService type. using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService))) { // Open the ServiceHost to create listeners // and start listening for messages. serviceHost.Open(); // The service can now be accessed. Console.WriteLine("The service is ready."); Console.WriteLine("Press to terminate service."); Console.WriteLine(); Console.ReadLine(); } }

When a service is hosted in Internet Information Services (IIS) or Windows Process Activation Service (WAS), the base address of the service is provided by the hosting environment. In the self-hosted case, you must specify the base address yourself. This is done using the add element, child of , child of , child of as demonstrated in the following sample configuration.

...

When you run the sample, the operation requests and responses are displayed in both the service and client console windows. Press ENTER in each console window to shut down the service and client.

To set up, build, and run the sample

Ensure that you he performed the One-Time Setup Procedure for the Windows Communication Foundation Samples.

To build the C# or Visual Basic .NET edition of the solution, follow the instructions in Building the Windows Communication Foundation Samples.

To run the sample in a single- or cross-computer configuration, follow the instructions in Running the Windows Communication Foundation Samples.

See also AppFabric Hosting and Persistence Samples

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至lsinopec@gmail.com举报,一经查实,本站将立刻删除。

上一篇 没有了

下一篇没有了