首页 新闻 会员 周边 捐助

ServiceHost.Open出现"函数不正确错误"

0
悬赏园豆:10 [已关闭问题]

我的WCF用BasicHttpBinding配置,出现了"函数不正确的错误"

代码如下 :

[DataContract]
    public class User
    {
        private string _name;
        private int _age;
        [DataMember]
        public string Name
        {
            get{return _name;}
            set{_name=value;}
        }
        [DataMember]
        public int Age
        {
            get{return _age;}
            set{_age=value;}
        }
        public User(string name,int age)
        {
            _name=name;
            _age=age;
        }
    }
    [ServiceContract]
    public interface IContact
    {
        [OperationContract]
        User GetUserInfo(string name);
    }

 

 public class Contact : IContact
    {
        List<User> users = new List<User>();
        public Contact()
        {
            users.Add(new User("trampt", 23));
            users.Add(new User("stray", 25));
            users.Add(new User("cnblogs", 25));
        }
        public User GetUserInfo(string name)
        {
            return users.Find(u => u.Name == name);
        }
    }

            using(ServiceHost host=new ServiceHost(typeof(Contact),new Uri("http://localhost:8092/Contact")))
            {
                host.AddServiceEndpoint(typeof(MyLibrary.IContact), new BasicHttpBinding(), String.Empty);
                ServiceMetadataBehavior behavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
                if (behavior == null)
                {
                    behavior = new ServiceMetadataBehavior();
                    behavior.HttpGetEnabled = true;
                    behavior.HttpGetUrl = new Uri("http://localhost:8092/Contact");
                    host.Description.Behaviors.Add(behavior);
                }
                else
                {

                    behavior.HttpGetEnabled = true;
                    behavior.HttpGetUrl = new Uri(http://localhost:8092/Contact);
                }
                host.Open();//这里出现函数不正确的错误

               Console.ReadLine();

}

 

孤城浪子的主页 孤城浪子 | 初学一级 | 园豆:197
提问于:2009-03-27 16:23
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册