WCF 서비스 인터페이스 :WCF 호출이 실패 <MyType>
[ServiceContract]
public interface ITest
{
[OperationContract]
int TestCall(GenericType<MyType> x);
[OperationContract]
int TestAnotherCall(GenericType<MyOtherType> x);
}
[DataContract(Name = "GenericType")]
[KnownType(typeof(List<MyType>))]
[KnownType(typeof(List<MyOtherType>))]
public class GenericType<T>
{
[DataMember]
public List<T> Data
{
get { return data; }
set { data = value; }
}
}
WCF 서비스 구현 :
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class Test : ITest
{
public int TestCall(GenericType<MyType> x)
{
return x.Data.Count;
}
public int TestAnotherCall(GenericType<MyOtherType> x)
{
return x.Data.Count;
}
}
CLIENT
List<MyType> list = from a in ctx.Table
select new MyType (a.Field1, a.Field2, a.Field3).ToList();
GenericType gt = new GenericType();
gt.Data = list;
using(WCFClient client = new WCFClient())
{
client.TestCall(gt);
client.Close();
}
오류 :
원격 서버에서 예기치 않은 응답을 보냈습니다 : (400) 잘못된 요청.
"gt.Data"에 NULL을 전달하면 ... 정상적으로 작동합니다.
참고 : 당신은 그것을 포함 할 수있는 각 클래스에 대한 KnownType 속성 GenericType 속성 필요
When I put the mouse over the gt.Data ...the hint shows as MyType[]
Not sure if that's expected.After some review, I noticed that the Client Service only knows about
the 1st [KnownType] stated, in my case the List. No knowledge of List ....
Is that expected when you put various [KnownType] on the WCF Interface?
클라이언트에서 GenericType을 사용하여 10 가지 유형을 사용할 경우 ... KnownType (typeof (XXX))? –
그냥 "GetKnownType"이 어디서 왔는지 확인하십시오. –
글쎄, 시험 ple [msdn] (http://msdn.microsoft.com/en-us/library/ms730167.aspx)에서 잘못 복사되었습니다 ... – erikH