WCF 操作协定,参数类型为 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);

最新更新