2

I want to use Cookie based authentication in P6 web service and I followed below two links

  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

Now I am able to Login with cookie based authentication but when I tries to proceed the next step I am strucked.

For eg. I want to create a new activity in P6 DB, I followed the below steps.

  1. Login to system (create a Cookie Container) : I added service reference for 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. Create the Activity : I add service reference for 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];
    

The issue is coming in second step, I am not able to create ActivityPortBinding class.

Error : The type or namespace name 'ActivityPortBinding' could not be found (are you missing a using directive or an assembly reference?)

  1. Can you please help me to find where I went wrong in the above code?
  2. Am I calling right Login() in step 1?
  3. Which Reference I should use to ActivityPortBinding class in Step2?

Thanks in Advance!

2 Answers2

0

Once you referenced the activity web service, you should just create an AcitvityService object and assign the cookiecontainer to the ActivityService Object. Something like following assuming your web service folder for activity service is named ActivityWS and your authentication service is named 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);    

  }
0
act1.ReadActivities(act)

This line of code is giving null or array length zero. There is already data loaded P6. Whether there is any setting to be done on P6 side

Chris Catignani
  • 5,040
  • 16
  • 42
  • 49