2017-01-20 42 views
0

我託管WCF服務我的服務和數據契約Windows應用程序WCF OperationContract的帶參數類型的對象

[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測試服務,越來越像「解串器並不知道哪種類型的誤差反序列化。檢查被序列化的類型是否與這裏的輸入代碼類型具有相同的合約被反序列化。「

+0

你得到的錯誤是什麼? – Tim

+0

你從哪裏得到這個錯誤? – Tim

回答

0

我認爲你只需要將錯誤契約屬性從類中移動到方法上。

[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); 
相關問題