Namespace.References
是一个PCL Profile 78
项目,其中包含对Web服务(asmx
)的引用。由于配置文件不支持整个服务模型堆栈,因此仅以APM样式生成异步方法。
从传统的C#控制台项目(引用为库)调用GetLoggedInUser
时,服务调用成功完成。
但是,当从Xamarin.Droid / Xamarin.Forms
项目中执行相同的服务调用时,服务调用成功完成,但响应不完整。响应仅填充基本响应类中的IsSuccessful
值。
见下文
public partial class GetUserResponse : GatewayResponseBase {
private User signedInUserField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public User SignedInUser {
get {
return this.signedInUserField;
}
set {
this.signedInUserField = value;
this.RaisePropertyChanged("SignedInUser");
}
}
}
public abstract partial class GatewayResponseBase : object, System.ComponentModel.INotifyPropertyChanged {
private bool isSuccessfulField;
private string messageField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public bool IsSuccessful {
get {
return this.isSuccessfulField;
}
set {
this.isSuccessfulField = value;
this.RaisePropertyChanged("IsSuccessful");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=1)]
public string Message {
get {
return this.messageField;
}
set {
this.messageField = value;
this.RaisePropertyChanged("Message");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
我以下列方式调用服务
const string username = "user";
const string password = "pass";
var response = Task<GetUserResponse>.Factory.FromAsync(Service.BeginGetLoggedInUser,
Service.EndGetLoggedInUser,
username, password, null).Result;
在传统的控制台应用下,response.SignedInUser
已正确填充。在移动平台response.SignedInUser
下执行时调用呼叫始终为null
;
服务设置如下
var service = new SoapClient();
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
service.Endpoint.Address = new EndpointAddress("https://address/Service.asmx");
var Service = (IService) service;
以下面的方式调用服务会产生与每个平台上相关调用相同的结果(即传统的控制台应用程序与移动平台)。
service.GetServicesCompleted += (sender, args) =>
{
var value = args.Result;
};
service.GetServicesAsync(username, password);
为什么服务调用会以完成时只填充部分信息的方式失败
由于