WCFサービスINTERFACE: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)Bad Request。
"gt.Data"にNULLを渡すと正常に動作します。
注:
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種類の異なる型を使用すると、10種類のサーバークラスを宣言する必要があることを意味します(KnownType(typeof (XXX))? –
「GetKnownType」はどこから来たのですか? –
(msdn)(http://msdn.microsoft.com/en-us/library/ms730167.aspx)から誤ってコピーされました... – erikH