国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Windows服務承載WCF

2019-11-17 01:37:30
字體:
來源:轉載
供稿:網友

Windows服務承載WCF

Source文件

-------------------------

  1 using System;  2 using System.Collections.Generic;  3 using System.Linq;  4 using System.Text;  5   6 using System.ComponentModel;  7 using System.ServiceModel;  8 using System.ServicePRocess;  9 using System.Configuration; 10 using System.Configuration.Install; 11  12 namespace Microsoft.ServiceModel.Samples 13 { 14     // Define a service contract. 15     [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")] 16     public interface ICalculator 17     { 18         [OperationContract] 19         double Add(double n1, double n2); 20         [OperationContract] 21         double Subtract(double n1, double n2); 22         [OperationContract] 23         double Multiply(double n1, double n2); 24         [OperationContract] 25         double Divide(double n1, double n2); 26     } 27  28     // Implement the ICalculator service contract in a service class. 29     public class CalculatorService : ICalculator 30     { 31         // Implement the ICalculator methods. 32         public double Add(double n1, double n2) 33         { 34             double result = n1 + n2; 35             return result; 36         } 37  38         public double Subtract(double n1, double n2) 39         { 40             double result = n1 - n2; 41             return result; 42         } 43  44         public double Multiply(double n1, double n2) 45         { 46             double result = n1 * n2; 47             return result; 48         } 49  50         public double Divide(double n1, double n2) 51         { 52             double result = n1 / n2; 53             return result; 54         } 55     } 56  57     public class CalculatorWindowsService : ServiceBase 58     { 59         public ServiceHost serviceHost = null; 60         public CalculatorWindowsService() 61         { 62             // Name the Windows Service 63             ServiceName = "WCFWindowsServiceSample"; 64         } 65  66         public static void Main() 67         { 68             ServiceBase.Run(new CalculatorWindowsService()); 69         } 70  71         // Start the Windows service. 72         protected override void OnStart(string[] args) 73         { 74             if (serviceHost != null) 75             { 76                 serviceHost.Close(); 77             } 78  79             // Create a ServiceHost for the CalculatorService type and 80             // provide the base address. 81             serviceHost = new ServiceHost(typeof(CalculatorService)); 82  83             // Open the ServiceHostBase to create listeners and start 84             // listening for messages. 85             serviceHost.Open(); 86         } 87  88         protected override void OnStop() 89         { 90             if (serviceHost != null) 91             { 92                 serviceHost.Close(); 93                 serviceHost = null; 94             } 95         } 96     } 97  98     // Provide the ProjectInstaller class which allows 99     // the service to be installed by the Installutil.exe tool100     [RunInstaller(true)]101     public class ProjectInstaller : Installer102     {103         private ServiceProcessInstaller process;104         private ServiceInstaller service;105 106         public ProjectInstaller()107         {108             process = new ServiceProcessInstaller();109             process.Account = ServiceAccount.LocalSystem;110             service = new ServiceInstaller();111             service.ServiceName = "WCFWindowsServiceSample";112             Installers.Add(process);113             Installers.Add(service);114         }115     }116 }

app.config

-----------------------------

<?xml version="1.0" encoding="utf-8" ?><configuration>  <system.serviceModel>    <services>      <service behaviorConfiguration="CalculatorServiceBehavior" name="Microsoft.ServiceModel.Samples.CalculatorService">        <endpoint address="http://localhost:8000/ServiceModelSamples/service"          behaviorConfiguration="NewBehavior0" binding="wsHttpBinding"          contract="Microsoft.ServiceModel.Samples.ICalculator" />        <endpoint address="http://localhost:8000/ServiceModelSamples/service/mex"          binding="mexHttpBinding" contract="IMetadataExchange" />        <host>          <baseAddresses>            <add baseAddress="http://localhost:8000/ServiceModelSamples/service" />          </baseAddresses>        </host>      </service>    </services>    <behaviors>      <endpointBehaviors>        <behavior name="NewBehavior0" />      </endpointBehaviors>      <serviceBehaviors>        <behavior name="CalculatorServiceBehavior">          <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8000/Sample"            httpsGetEnabled="true" />          <serviceDebug includeExceptionDetailInFaults="false" />        </behavior>      </serviceBehaviors>    </behaviors>  </system.serviceModel></configuration>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海伦市| 汝南县| 广灵县| 九江市| 同江市| 淮北市| 深州市| 左云县| 库伦旗| 新化县| 朝阳县| 手游| 丰县| 山西省| 奉节县| 赤水市| 桃江县| 皋兰县| 灵丘县| 平塘县| 馆陶县| 武功县| 孝昌县| 南京市| 岱山县| 邓州市| 安乡县| 金阳县| 壤塘县| 鱼台县| 民权县| 留坝县| 井冈山市| 萨嘎县| 平潭县| 额济纳旗| 屯留县| 郯城县| 博湖县| 江华| 阳谷县|