我想通过我的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