简体   繁体   English

WCF OperationContract与对象类型的参数

[英]WCF OperationContract With Parameters Of Type Object

I am hosting WCF service in my Windows application with service and data contracts 我通过服务和数据合同在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";
    }
}

While testing service using WCFTestClient, getting error like "The deserializer has no knowledge of which type to deserialize. Check that the type being serialized has the same contract as the enter code here type being deserialized." 使用WCFTestClient测试服务时,出现类似“反序列化程序不知道要反序列化的类型的错误。请检查要序列化的类型是否与此处要反序列化的输入代码具有相同的约定。”

I think you just need to move the fault contract attribute from the class onto the methods. 我认为您只需要将故障合同属性从类移到方法上即可。

   [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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM