天下

记录修行的印记

精简版本WCF DEMO

using System;
using System.ServiceModel; //添加System.ServiceModel引用
using System.ServiceModel.Channels;

namespace ConsoleApplication1
{
    [ServiceContract]
    
public interface IHelloWCF
    {
        [OperationContract]
        
void Say(string input);
    }
    
public sealed class HelloService : IHelloWCF
    {
        
public void Say(string input)
        {
            Console.WriteLine(
"Hello {0}", input);
        }
    }
    
class Program
    {
        
static void Main(string[] args)
        {
            Uri address 
= new Uri("http://127.0.0.1:8733/IHelloWCF");
            BasicHttpBinding binding 
= new BasicHttpBinding();
            ServiceHost svc 
= new ServiceHost(typeof(HelloService));
            svc.AddServiceEndpoint(
typeof(IHelloWCF), binding, address);
            svc.Opened 
+= delegate {
                Console.WriteLine(
"The HelloWCF receiving application is ready");
            };
            svc.Open();

            ChannelFactory
<IHelloWCF> factory = new ChannelFactory<IHelloWCF>(binding,new EndpointAddress(address));
            IHelloWCF proxy 
= factory.CreateChannel();
            proxy.Say(
"张三");
            proxy.Say(
"李四");
            proxy.Say(
"王二麻子");


            Console.ReadLine();
            svc.Close();
        }
    }
}

posted on 2016-06-16 09:46 天下 阅读(232) 评论(0)  编辑 收藏 引用 所属分类: C#WCF


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿(4)

随笔分类(378)

随笔档案(329)

链接

最新随笔

搜索

最新评论