我想通過我的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; }
}
}
一些方法被抑制
你真的嘗試將兩個類序列化到一個文件,看看會發生什麼? – 2012-03-26 10:32:16
你能提供A類和B類的代碼嗎? – ClayKaboom 2012-03-26 10:32:48
@大衛:不,我沒有嘗試過。但是,它應該重要嗎?因爲webservice可以正確返回類型B. – waqaslam 2012-03-26 10:45:33