0

我想阅读.net 中使用 PSI Web 服务的项目列表。不知道怎么回事,请求web方法的时候总是报“Unhandled Communication Fault occurred”异常。

有人可以帮我修复它吗?

我正在使用 VS 2010

  1. 使用网络引用添加并使用以下代码,(给出实际用户名和密码)网络参考网址:servername/ProjectServerName/_vti_bin/PSI/project.asmx?wsdl

    svcProject.Project prj2 = 新 svcProject.Project(); prj2.Credentials = new NetworkCredential("testuser", "testpassword"); svcProject.ProjectDataSet lst2 = prj2.ReadProjectList();

  2. 我也用下面的代码尝试了 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 中对用户权限或身份验证进行更改

提前致谢

4

1 回答 1

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;
}
于 2013-08-01T16:39:17.233 回答