2012-03-26 86 views
-1

我想通过我的asmx web服务运行在.net 4.0上发送自定义类的对象,但我得到的是一个空的响应。见下文:ASMX web服务不返回任何结果

<soap:Body> 
    <ActivateResponse xmlns="http://tempuri.org/"> 
     <ActivateResult />        <!-- why is this empty --> 
    </ActivateResponse> 
</soap:Body> 

然而,如果我从类修改我的方法和改变返回类型例如甲,则它返回对象正确的所有属性。见下:

<ActivateResponse xmlns="http://tempuri.org/"> 
    <ActivateResult> 
     <BtAddress>string</BtAddress> 
     <Name>string</Name> 
     <Number>string</Number> 
    </ActivateResult> 
</ActivateResponse> 

我想知道为什么它发生?我可以责怪不正当序列号A但没有什么幻想我参与我的课堂文件。两个类文件在内容方面几乎相似,并且不包含任何Serialize属性。

那么,为什么web服务返回一种类型,而不是另一种?


A类

public class A 
{ 
    private string code; 
    private bool isValid; 
    private int maxUniqueActivations; 
    private DateTime dateAdded; 
    private Customer customer = null; 
    private bool _initAsEmpty = false; 


    public License() 
    { 
     _initAsEmpty = true; 
    } 

    public string LicenseCode 
    { 
     get { return code; } 
     //set { code = String.IsNullOrWhiteSpace(value)? null : value.Trim(); } 
    } 
    //If i change return type to Customer, it works too 
    //so i dont think it should be blamed 
    public Customer Customer 
    { 
     get { return customer; } 
    } 
    public bool IsValid 
    { 
     get { return isValid; } 
    } 
    public int MaxUniqueActivations 
    { 
     get { return maxUniqueActivations; } 
    } 
    public DateTime DateAdded 
    { 
     get { return dateAdded; } 
    } 
} 

B类

public class Phone 
{ 
    private string btAddress, name, number; 
    private bool isValid; 
    private DateTime dateAdded; 
    private bool _initAsEmtpy = false; 

    public Phone() 
    { 
     _initAsEmtpy = true; 
    } 

    public string BtAddress 
    { 
     get { return btAddress; } 
     set { btAddress = string.IsNullOrWhiteSpace(value) ? null : value.Replace(":", "").Trim(); } 
    } 
    public string Name 
    { 
     get { return name; } 
     set { name = string.IsNullOrWhiteSpace(value) ? null : value.Trim(); } 
    } 
    public string Number 
    { 
     get { return number; } 
     set { number = string.IsNullOrWhiteSpace(value) ? null : value.Trim(); } 
    } 
    public bool IsValid 
    { 
     get { return isValid; } 
    } 
    public DateTime DateAdded 
    { 
     get { return dateAdded; } 
    } 
} 

一些方法被抑制

+0

你真的尝试将两个类序列化到一个文件,看看会发生什么? – 2012-03-26 10:32:16

+1

你能提供A类和B类的代码吗? – ClayKaboom 2012-03-26 10:32:48

+0

@大卫:不,我没有尝试过。但是,它应该重要吗?因为webservice可以正确返回类型B. – waqaslam 2012-03-26 10:45:33

回答

2

为了是可序列化的,一个类必须在其属性上有公共setter。这就是A类和B类之间的区别,也是A不会序列化的原因。

大概:)

+0

我认为你的意思是公共设置者*的属性*,而不是*方法* – 2012-03-26 16:23:13

+0

我说过吗?哦,亲爱的 - 显然没有足够的咖啡。欢呼@约翰桑德斯编辑它。 – 2012-03-26 22:02:16

0

我认为问题可能与Customer类。也许它是私人或什么的。尝试检查出来。