2014-07-10 175 views
1

我想在P6 Web服務使用基於Cookie的身份驗證寫通過P6 Web服務在P6DB數據,我採取了以下兩個鏈接如何閱讀和使用C#

  1. http://docs.oracle.com/cd/E16281_01/Technical_Documentation/Web_Services/ProgrammersGuide/Logging_into_Primavera_Web_Services.htm#dotnetexample
  2. http://docs.oracle.com/cd/E16281_01/Technical_Documentation/Web_Services/ProgrammersGuide/whnjs.htm

現在我可以使用基於cookie的身份驗證進行登錄,但是當我嘗試着手進行下一步操作時,我被攻擊了。

例如,我想在P6 DB中創建一個新的活動,我遵循以下步驟。

  1. 登錄到系統(創建Cookie容器):我添加服務引用了AuthenticationService.wsdl

    System.Net.CookieContainer cookieContainer; 
    public void Login(String userName, String password) 
    { 
    
        AuthenticationServiceWebRef.AuthenticationService authService = new AuthenticationServiceWebRef.AuthenticationService(); 
        authService.CookieContainer = new System.Net.CookieContainer(); 
    
        authService.Url = ConfigurationManager.AppSettings["WSAuthenticationService"]; 
        AuthenticationServiceWebRef.Login loginObj = new AuthenticationServiceWebRef.Login(); 
        loginObj.UserName = userName; 
        loginObj.Password = password; 
        loginObj.DatabaseInstanceId = 1; 
        loginObj.DatabaseInstanceIdSpecified = true; 
        AuthenticationServiceWebRef.LoginResponse loginReturn = authService.Login(loginObj); 
        cookieContainer = authService.CookieContainer; 
    } 
    
  2. 創建活動:?我增加對ActivityService服務引用WSDL

     Login(WSUsername, WSPassword); 
         ActivityPortBinding apb = new ActivityPortBinding(); 
         apb.CookieContainer = cookieContainer; 
         apb.Url = ConfigurationManager.AppSettings["WSGetDataByID"]; 
         Activity[] acts; 
         acts = new Activity[1]; 
    
         Activity activity = null; 
         for (int i = 0; i < 1; i++) 
         { 
          activity = new Activity(); 
          activity.ProjectObjectId = iProjectObjectID; 
          activity.ProjectObjectIdSpecified = true; 
          activity.Id = "P6 Test" + (i + 1); 
          activity.Name = "P6 Test" + (i + 1); 
          acts[i] = activity; 
         } 
         int [] arrayObjectIDs= apb.CreateActivities(acts); 
         iRetActivityObjectID = arrayObjectIDs[0]; 
    

該問題即將出現在第二步,我無法創建ActivityPortBinding類秒。

錯誤:類型或命名空間名稱「ActivityPortBinding」找不到(是否缺少using指令或程序集引用?)

  1. 能否請你幫我找到我哪裏做錯了上面的代碼?
  2. 我打電話正確登錄()在第1步?
  3. 我應該使用哪一個參考到Step2中的ActivityPortBinding類?

在此先感謝!

回答

0

一旦您引用了活動Web服務,您應該創建一個AcitvityService對象並將該Cookiecontainer分配給ActivityService對象。類似如下假設您的Web服務文件夾的活動服務名爲ActivityWS和您的驗證服務名爲AuthenWS

static System.Net.CookieContainer cookieContainer; 
    static void Main(string[] args) 
    { 

     AuthenWS.AuthenticationService authService = new AuthenWS.AuthenticationService(); 
     authService.CookieContainer = new System.Net.CookieContainer(); 


     AuthenWS.Login loginObj = new AuthenWS.Login(); 
     loginObj.UserName = "xxx"; 
     loginObj.Password = "yyy*"; 
     loginObj.DatabaseInstanceId = 1; 
     loginObj.DatabaseInstanceIdSpecified = true; 
     AuthenWS.LoginResponse loginReturn = authService.Login(loginObj); 
     if (loginReturn.Return == true) cookieContainer = authService.CookieContainer; 
     else { 
      Console.WriteLine ("login failed"); 
      return; 
     } 

     ActivityWS.ActivityService acService = new ActivityWS.ActivityService; 
     acService.CookieContainer = cookieContainer; 
     ActivityWS.Activity [] acts; 
     acts = new ActivityWS.Activity[1]; 

     ActivityWS.Activity activity = null; 
     for (int i = 0; i < 10; i++) 
     { 
     activity = new ActivityWS.Activity(); 
     activity.ProjectObjectId = iProjectObjectID; 
     activity.ProjectObjectIdSpecified = true; 
     activity.Id = "P6 Test" + (i + 1); 
     activity.Name = "P6 Test" + (i + 1); 
     acts[i] = activity; 
     } 

     acService.CreateActivities(acts);  

    }