我想在.net中使用PSI Web服务阅读项目列表。我不知道出了什么问题,我总是在请求Web方法时遇到“未处理的通信故障”异常。
有人可以帮我解决问题。
我正在使用VS 2010
使用网络参考添加并使用以下代码,(给出实际的用户名和密码) web ref url:servername / ProjectServerName / _vti_bin / PSI / project.asmx?wsdl
svcProject.Project prj2 = new svcProject.Project(); prj2.Credentials = new NetworkCredential(“testuser”,“testpassword”); svcProject.ProjectDataSet lst2 = prj2.ReadProjectList();
我使用以下代码
尝试了WCF参考ProjectSoapClient.ProjectSoapClient prj = new ProjectSoapClient.ProjectSoapClient(); prj.ClientCredentials.Windows.ClientCredential = new NetworkCredential(“testuser”,“testpassword”,“SDP”); prj.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; ProjectDataSet lst = prj.ReadProjectList();
我总是得到“发生未处理的通信错误”错误,
有些人可以帮助在Project Server 2010中对用户权限或身份验证更改进行更改
提前致谢
答案 0 :(得分:0)
你是否正在尝试捕获soapexception?
catch (SoapException ex)
{
PSLib.PSClientError error = new PSLib.PSClientError(ex);
PSLib.PSErrorInfo[] errors = error.GetAllErrors();
PSLib.PSErrorInfo thisError;
for (int i = 0; i < errors.Length; i++)
{
thisError = errors[i];
}
string StrException = ex.ToString() + " \r\nInner Exception: " + ex.InnerException.ToString();
}
您是否尝试过login.asmx服务进行身份验证而非进行模拟
//Creating a new service client object
ProjectDerived projectSvc = new ProjectDerived();
projectSvc.Url = projectServerUrl + "Project.asmx";
projectSvc.Credentials = CredentialCache.DefaultCredentials;
projectSvc.CookieContainer = GetLogonCookie();
projectSvc.EnforceWindowsAuth = isWindowsUser;
// Get a CookieContainer property from the derived LoginWindows object.
private static CookieContainer GetLogonCookie()
{
// Create an instance of the loginWindows object.
LoginWindowsDerived loginWindows = new LoginWindowsDerived();
loginWindows.EnforceWindowsAuth = true;
loginWindows.Url = projectServerUrl + "LoginWindows.asmx";
loginWindows.Credentials = CredentialCache.DefaultCredentials;
loginWindows.CookieContainer = new CookieContainer();
if (!loginWindows.Login())
{
// Login failed; throw an exception.
throw new UnauthorizedAccessException("Login failed.");
}
return loginWindows.CookieContainer;
}