Hosting WCF service inside a Windows Forms application

前端 未结 3 1203
北荒
北荒 2020-12-03 03:50

I need to host a WCF service inside a Windows Forms application and call the WCF service from a Windows service that will send data to the WCF service which will show it in

3条回答
  •  孤街浪徒
    2020-12-03 04:50

    Use the below code to host the WCF service in a Windows Forms application:

    using System.ServiceModel.Channels;
    ServiceHost host = new ServiceHost(typeof(MyNamespace.OrderService));
    BindingElementCollection bec = new BindingElementCollection();
    SymmetricSecurityBindingElement ssbe = new
    SymmetricSecurityBindingElement();
    ssbe.LocalServiceSettings.InactivityTimeout = new TimeSpan(0, 10, 0);
    bec.Add(ssbe);
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpsTransportBindingElement());
    CustomBinding customBinding = new CustomBinding(bec);
    host.AddServiceEndpoint(typeof(MyNamespace.IOrderService),customBinding,"http://localhost:8000/O
    rderService/");
    

提交回复
热议问题