我正在为 Windows Phone 7 开发一个应用程序。我正在尝试使用由我试图从中获取信息的网站提供的服务。我正在使用异步请求。因此,如果我尝试在没有任何身份验证的情况下从网站获取信息,我会使用以下代码:
EventSrv.EventSrvSoapClient client = new EventSrv.EventSrvSoapClient();
client.GetAppointmentsAsync();
client.GetAppointmentsCompleted += new EventHandler<EventSrv.GetAppointmentsCompletedEventArgs>(events_completed);
它工作正常。但是,一旦我想使用需要身份验证的网站上的服务,我就会得到一个
CommunicationException:_innerException:“服务器返回错误:未找到”
在
public L2P.DocumentsService.GetDocumentsResponse EndGetDocuments(System.IAsyncResult result)
{
object[] _args = new object[0];
//Between this line
L2P.DocumentsService.GetDocumentsResponse _result = ((L2P.DocumentsService.GetDocumentsResponse)(base.EndInvoke("GetDocuments", _args, result)));
//and this line
return _result;
}
我通过以下方式传递凭据:
DocumentsService.BaseServiceSoapClient docClient = new DocumentsService.BaseServiceSoapClient();
docClient.ClientCredentials.UserName.UserName = Variables.username;
docClient.ClientCredentials.UserName.Password = Variables.password;
docClient.GetDocumentsCompleted += new EventHandler<DocumentsService.GetDocumentsCompletedEventArgs>(getDocumentsCompleted);
docClient.GetDocumentsAsync();
我是否通过凭据实际上并不重要,我得到了同样的异常。我真的不知道问题是什么,也许它与身份验证无关。我已经阅读了关于 CommunicationException 的所有文章,但它们无法解决我的问题。
任何帮助将不胜感激!