我有一个带有服务接口的 WCF 服务
[ServiceContract]
public interface IMyService
{
[OperationContract]
[ServiceKnownType(typeof(Person))]
[ServiceKnownType(typeof(Employee))]
IPerson GetPerson();
}
我的 GetPerson 实现是
public IPerson GetPerson()
{
IPerson obj = new Person();
obj.FirstName = "Bhuvan";
obj.LastName = "Ram";
return obj;
}
在我的客户中,我使用的很简单
KnownType.MyServiceClient obj = new KnownType.MyServiceClient();
Person objp = (Person)obj.GetPerson()'
但是当我尝试访问时,我收到一个错误
基础连接已关闭:连接意外关闭。
我的堆栈跟踪是这样的
在 System.Net.HttpWebRequest.GetResponse()
在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
在 System.Net.HttpWebRequest.GetResponse()
在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest .WaitForReply(时间跨度超时)..
我的员工班是
> [DataContract(Name = "Employee")] [KnownType(typeof(IEmployee))]
public class Employee:IEmployee { [DataMember] public string EmployeeName { get;set; } }> 我的人员类是 [DataContract(Name = "Person")] [KnownType(typeof(IPerson))]
public class Person: IPerson {
#region IPerson Members [DataMember(Name = "FirstName")] public string FirstName { get; 放; }
[DataMember(Name = "LastName")]
public string LastName { get; set; }
#endregion
}
我该如何解决这个问题?