zoukankan      html  css  js  c++  java
  • WCF实现客户端和服务端

    service side

    1.定义ServiceContract:

    2.new a ServiceHost

    3. add endpoint

    using System.ServiceModel;
    
    namespace Service
    {
        class Program
        {
            static void Main(string[] args)
            {
                Uri address = new Uri("http://localhost:8000/myservice");
                using (ServiceHost host = new ServiceHost(typeof(MyService), address))      //MyService是服务方法的类库名称
                {
                    host.AddServiceEndpoint(typeof(IMyService), new BasicHttpBinding(), address);   //IMyService是服务接口类库名称
                    host.Open();
                    Console.ReadLine();
                }
            }
    
        }
    
        [ServiceContract]
        public interface IMyService
        {
            [OperationContract]
            string GetService();
        }
    
        public class MyService : IMyService
        {
    
            public string GetService()
            {
                return "Got Service!";
            }
        }
    }

    client side: get proxy, service 调用

    using System.ServiceModel;
    
    namespace Client
    {
        class Program
        {
            static void Main(string[] args)
            {
                IMyService proxy = ChannelFactory<IMyService>.CreateChannel(new BasicHttpBinding(),
                    new EndpointAddress("http://localhost:8000/myservice"));
                Console.WriteLine(proxy.GetService());
                Console.ReadLine();
            }
        }
    
        [ServiceContract]
        public interface IMyService
        {
            [OperationContract]
            string GetService();
        }
    
    }

     bdc = new BaseDataClient(new BasicHttpBinding(), new EndpointAddress(Configurator.GetConfigValue("stsurl")));
        <add key="stsurl" value="
    http://192.168.100.1:8888/CoreData.svc" />

  • 相关阅读:
    SDNU 1311.Binomial Coeffcients
    SDNU 1306.兑数
    SDNU 1272.SL的秘密
    SDNU 1270.超超的难题
    XCode 自动化打包总结
    Xrun 将 app 转化为 IPA
    mac终端下运行shell脚本
    ios 检测应用程序升级问题
    在iis6.0公布asp.net mvc3网站
    IOS 中 NSArray
  • 原文地址:https://www.cnblogs.com/shy1766IT/p/5196692.html
Copyright © 2011-2022 走看看