码迷,mamicode.com
首页 > 其他好文 > 详细

wcf-学习

时间:2021-04-06 14:33:05      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:threading   poi   ati   using   pac   desc   task   ons   name   

将服务寄宿与控制台:

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Text;
using System.Threading.Tasks;
using MyWcfService;

namespace Host
{
    class Program
    {
        static void Main(string[] args)
        {
            using (ServiceHost host = new ServiceHost(typeof(Service1)))
            {

                host.AddServiceEndpoint(typeof(IService1), new WSHttpBinding(),
 "http://127.0.0.1:8733/Service1");
                if (host.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
                {

                    ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                    behavior.HttpGetEnabled = true;
                    behavior.HttpGetUrl = new Uri("http://127.0.0.1:8733/Service1/metadata");
                    host.Description.Behaviors.Add(behavior);

                }

                host.Opened += delegate

                {
                    Console.WriteLine("BookService,按任意键终止服务!");
                };

                host.Open();
                Console.Read();

            }
        }
    }
}

客户端

1.添加服务引用

技术图片

 

 2.

 private void button1_Click(object sender, EventArgs e)
        {
            Service1Client service1Client = new Service1Client();
            MessageBox.Show(service1Client.GetData(2));
        }

 

wcf-学习

标签:threading   poi   ati   using   pac   desc   task   ons   name   

原文地址:https://www.cnblogs.com/dangnianxiaoqingxin/p/14616069.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!