![](/img/trans.png)
[英]WCF OperationContract - which generic collection type should I expose?
[英]WCF OperationContract With Parameters Of Type Object
我通过服务和数据合同在Windows应用程序中托管WCF服务
[ServiceContract]
[FaultContract(typeof(object))]
[ServiceKnownType(typeof(busSample))]
public interface IUPSBusinessTier
{
[OperationContract]
string TestMethod1(string astrName);
[OperationContract]
void TestMethod2(busSample abusSample);
[OperationContract]
busSample TestMethod3(string astrName);
[OperationContract]
string TestMethod4(object astrName);
}
[DataContract]
public class busSample
{
[DataMember]
public string istrName { get; set; }
public busSample()
{
this.istrName = "ABC";
}
}
使用WCFTestClient测试服务时,出现类似“反序列化程序不知道要反序列化的类型的错误。请检查要序列化的类型是否与此处要反序列化的输入代码具有相同的约定。”
我认为您只需要将故障合同属性从类移到方法上即可。
[ServiceContract]
//[FaultContract(typeof(object))]
[ServiceKnownType(typeof(busSample))]
public interface IUPSBusinessTier
{
[FaultContract(typeof(object))]
[OperationContract]
string TestMethod1(string astrName);
[FaultContract(typeof(object))]
[OperationContract]
void TestMethod2(busSample abusSample);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.