【问题标题】:Windows Phone 7 Silverlight Service References CommunicationException: "Server returned an error: Not Found"Windows Phone 7 Silverlight 服务引用 CommunicationException:“服务器返回错误:未找到”
【发布时间】:2011-12-30 23:06:45
【问题描述】:

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

任何帮助将不胜感激!

【问题讨论】:

  • 这有帮助吗? karlshifflett.wordpress.com/2011/04/25/… 没有深入研究,它看起来很相似。
  • 感谢您的回复!不幸的是,我找不到任何有用的信息。我需要提及的是,我正在尝试连接到使用基本身份验证的 SharePoint 2007 站点。默认情况下,所有 SharePoint 服务均已停用,只有少数已启用。

标签: silverlight windows-phone-7 service reference communicationexception


【解决方案1】:

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

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

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

【讨论】:

  • 我有soap api并使用apikey来验证所有请求。你能告诉我如何添加apikey。
猜你喜欢
  • 2010-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多