0

我正在为 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 的所有文章,但它们无法解决我的问题。

任何帮助将不胜感激!

4

1 回答 1

0

我终于想通了!服务器使用基本身份验证,默认情况下将标头设置为“POST”。所以我需要修改标题,将其设置为“基本”并添加凭据。此外,

CommunicationException:“服务器返回错误:未找到”

如果有任何未处理的异常,总是出现。因此,您需要调试并检查 _innerException 以获取更多信息。

于 2011-11-18T15:22:54.963 回答