我的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();
}