我正在编写一个调用 Web 服务对客户端进行身份验证的 C# 客户端。我使用添加服务引用将 wsdl 文件添加到我的项目中,并且成功生成了代理类。
我正在创建将像这样使用的对象的新实例:
authenticateAccessPortTypeClient client = new authenticateAccessPortTypeClient();
authDetails details = new authDetails();
returnResult result = new returnResult();
当用户需要进行身份验证时,这是我的代码:
// This is details that needs to be passed in the header of the SOAP Envelope
details.key = "some key as string";
details.mode = "the mode as string";
// This is a parameter that is passed in the body of the SOAP Envelope
string memKey = "the member key as string";
result = client.authenticateAccess(details, memKey);
textBoxResult.Text = result.message;
我的肥皂响应如下所示:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:example="www.example.com">
<soapenv:Header/>
<soapenv:Body>
<example:authenticateAccessResponse>
<result>
<message>some string</message>
</result>
</example:authenticateAccessResponse>
</soapenv:Body>
</soapenv:Envelope>
returnResults 在生成的代理类中看起来像这样:
public partial class returnResult : object, System.ComponentModel.INotifyPropertyChanged {
private string messageField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
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));
}
}
}
我不断收到错误:对象引用未设置为对象的实例,returnResult 为空。