1 Reply Latest reply: Apr 15, 2014 5:08 PM by Ron M-Oracle RSS

    How to Get Data from Agile PLM to .Net Application ?

    3abf713d-c0ff-4c39-a293-0f96286149c3

      Hello,

      for a start, sorry about my English

      i'm trying make .Net Application to read some data from Agile PLM (C#)

      what are the ways to get the data from the Agile PLM to .Net Application ?

      1. What are the options ?

           - Core Web Service ?

      I tried to do as -  Simple .Net Samples Using Agile PLM Web Services in Microsoft Visual Studio (from Oracle Agile PLM Sample Code - SimpleWebServices.zip)

           Exception sequence ID : -1

           Exception ID : 60086

           Exception Message : Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

      there is modified code:

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using Microsoft.Win32;
      
      
      namespace ConsoleApplication1
      {
          class Program
          {
      
      
              static void Main(string[] args)
              {
                  Console.WriteLine("Enter the base Url : ");
                  String baseUrl = Console.ReadLine();
                  if (baseUrl.Length == 0)
                  {
                      baseUrl = "http://elmoagileapp.elmoil.local:7777/CoreService/services";
                  }
                  Console.WriteLine("Enter userName :");
                  String user = Console.ReadLine();
                  Console.WriteLine("Enter password :");
                  String password = "";
      
      
                  ConsoleKeyInfo info = Console.ReadKey(true);
                  while (info.Key != ConsoleKey.Enter)
                  {
                      if (info.Key != ConsoleKey.Backspace)
                      {
                          password += info.KeyChar;
                          info = Console.ReadKey(true);
                      }
                      else if (info.Key == ConsoleKey.Backspace)
                      {
                          if (!string.IsNullOrEmpty(password))
                          {
                              password = password.Substring
                              (0, password.Length - 1);
                          }
                          info = Console.ReadKey(true);
                      }
                  }
                  for (int i = 0; i < 6; i++)
                      Console.Write("*");
                  Program program = new Program();
                  System.Net.ICredentials cred = program.initialize(user, password);
      
      
                  while (true)
                  {
                      Console.WriteLine("\nMake a choice. Select from 1-6.");
                      Console.WriteLine("1. Create Part.");
                      Console.WriteLine("2. Delete Part.");
                      Console.WriteLine("3. Get Part.");
                      Console.WriteLine("4. Load Table.");
                      Console.WriteLine("5. Exit");
                      String choice = Console.ReadLine();
                      int value = Convert.ToInt32(choice);
                      switch (value)
                      {
                          case 1:
                              createObject(baseUrl, cred);
                              break;
                          case 2:
                              deleteObject(baseUrl, cred);
                              break;
                          case 3:
                              loadObject(baseUrl, cred);
                              break;
                          case 4:
                              loadTable(baseUrl, cred);
                              break;
                          case 5:
                              Console.WriteLine("Exit: Choice {0} selected.", value);
                              Environment.Exit(0);
                              break;
                          default:
                              Console.WriteLine("Choice {0} is not in between 1 to 6");
                              break;
                      }
                  }
              }
      
      
              private static void createObject(String url, System.Net.ICredentials cred)
              {
                  BusinessService.BusinessObjectService service = new BusinessService.BusinessObjectService();
                  service.Url = url + "/BusinessObject";
                  service.Credentials = cred;
                  BusinessService.CreateObjectRequestType request = new BusinessService.CreateObjectRequestType();
                  BusinessService.AgileCreateObjectRequest[] requests = new BusinessService.AgileCreateObjectRequest[1];
                  Console.WriteLine("Enter a Part Number : ");
                  String objectNumber = Console.ReadLine();
                  Console.WriteLine("Enter a Part Description : ");
                  String desc = Console.ReadLine();
                  requests[0] = new ConsoleApplication1.BusinessService.AgileCreateObjectRequest();
                  requests[0].classIdentifier = "Part"; //APIName of the part
                  BusinessService.AgileRowType dataRow = new BusinessService.AgileRowType();
                  dataRow.rowId = 0;
                  System.Xml.XmlElement[] anyElement = new System.Xml.XmlElement[2];
                  System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                  anyElement[0] = doc.CreateElement("number");
                  anyElement[0].SetAttribute("xmlns:xsi", "xs:string");
                  anyElement[0].InnerText = objectNumber;
                  anyElement[1] = doc.CreateElement("description");
                  anyElement[1].SetAttribute("xmlns:xsi", "xs:string");
                  anyElement[1].InnerText = desc;
                  dataRow.Any = anyElement;
                  requests[0].data = dataRow;
                  request.requests = requests;
                  BusinessService.CreateObjectResponseType response = service.createObject(request);
                  displayCreateObjectResponse(response);
              }
      
      
              private static void deleteObject(String url, System.Net.ICredentials cred)
              {
                  BusinessService.BusinessObjectService service = new BusinessService.BusinessObjectService();
                  service.Url = url + "/BusinessObject";
                  service.Credentials = cred;
                  BusinessService.DeleteObjectRequestType request = new BusinessService.DeleteObjectRequestType();
                  BusinessService.AgileDeleteObjectRequest[] requests = new BusinessService.AgileDeleteObjectRequest[1];
                  Console.WriteLine("Enter Part Number");
                  String str = Console.ReadLine();
                  requests[0] = new ConsoleApplication1.BusinessService.AgileDeleteObjectRequest();
                  requests[0].classIdentifier = "Part";
                  requests[0].objectNumber = str;
                  request.requests = requests;
                  BusinessService.DeleteObjectResponseType response = service.deleteObject(request);
                  Console.WriteLine("Status: " + response.statusCode);
              }
      
      
              private static void loadObject(String url, System.Net.ICredentials cred)
              {
                  BusinessService.BusinessObjectService service = new BusinessService.BusinessObjectService();
                  service.Url = url + "/BusinessObject";
                  service.Credentials = cred;
                  BusinessService.GetObjectRequestType request = new BusinessService.GetObjectRequestType();
                  BusinessService.AgileGetObjectRequest[] requests = new BusinessService.AgileGetObjectRequest[1];
                  Console.WriteLine("Enter Part Number:");
                  String str = Console.ReadLine();
                  requests[0] = new ConsoleApplication1.BusinessService.AgileGetObjectRequest();
                  requests[0].classIdentifier = "Part";
                  requests[0].objectNumber = str;
                  request.requests = requests;
                  BusinessService.GetObjectResponseType response = service.getObject(request);
                  displayGetObjectResponse(response);
      
      
              }
      
      
              private static void loadTable(String url, System.Net.ICredentials cred)
              {
                  TableService.TableService service = new TableService.TableService();
                  service.Url = url + "/Table";
                  service.Credentials = cred;
                  TableService.LoadTableRequestType request = new TableService.LoadTableRequestType();
                  TableService.RequestTableType[] requests = new TableService.RequestTableType[1];
                  Console.WriteLine("Enter Part Number:");
                  String str = Console.ReadLine();
                  Console.WriteLine("Enter Table Name : ");
                  String table = Console.ReadLine();
                  requests[0] = new TableService.RequestTableType();
                  requests[0].classIdentifier = "Part";
                  requests[0].objectNumber = str;
                  requests[0].tableIdentifier = table;
                  request.tableRequest = requests;
                  TableService.LoadTableResponseType response = service.loadTable(request);
                  displayloadTableResponse(response);
      
      
              }
      
      
              private static void displayloadTableResponse(ConsoleApplication1.TableService.LoadTableResponseType response)
              {
                  String statusCode = response.statusCode.ToString();
                  Console.WriteLine("Status: " + statusCode);
                  if (statusCode.ToUpper().Equals("SUCCESS"))
                  {
                      TableService.AgileTableType[] agileTable = response.tableContents;
                      TableService.TableIdentifierType tableIdentifier = agileTable[0].tableIdentifier;
                      Console.WriteLine("Class Name :" + tableIdentifier.className + " Object Name :"+tableIdentifier.objectName +" Table Name :" + tableIdentifier.tableName);
                  }
                  else
                  {
                      TableService.AgileExceptionListType[] exceptionList = response.exceptions;
                      for (int i = 0; (exceptionList != null) && (i < exceptionList.Length); i++)
                      {
                          System.Console.WriteLine("Exception sequence ID : " + exceptionList[i].id);
                          TableService.AgileExceptionType[] exception = exceptionList[i].exception;
                          for (int j = 0; (exception != null) && (j < exception.Length); j++)
                          {
                              System.Console.WriteLine("Exception ID : " + exception[j].exceptionId +
                                  "\n Exception Message : " + exception[j].message);
                          }
                      }
                      TableService.AgileWarningListType[] warningList = response.warnings;
                      for (int i = 0; (warningList != null) && (i < warningList.Length); i++)
                      {
                          System.Console.WriteLine("Warning sequence ID : " + warningList[i].id);
                          TableService.AgileWarningType[] warning = warningList[i].warning;
                          for (int j = 0; (warning != null) && (j < warning.Length); j++)
                          {
                              System.Console.WriteLine("Warning ID : " + warning[j].warningId +
                                  "\n Warning Message : " + warning[j].message);
                          }
                      }
                  }
              }
      
      
              private static void displayCreateObjectResponse(ConsoleApplication1.BusinessService.CreateObjectResponseType response)
              {
                  String statusCode = response.statusCode.ToString();
                  Console.WriteLine("Status: " + statusCode);
                  if (statusCode.ToUpper().Equals("SUCCESS"))
                  {
                      BusinessService.AgileCreateObjectResponse[] responses = response.responses;
                      //Since we are loading on
                      for (int i = 0; i < responses.Length; i++)
                      {
                          BusinessService.AgileObjectType agileObject = responses[i].agileObject;
                          BusinessService.ObjectIdentifierType objID = agileObject.objectIdentifier;
                          displayObjectID(objID);
                          System.Xml.XmlElement[] data = agileObject.Any;
                      }
                  }
                  else
                  {
                      BusinessService.AgileExceptionListType[] exceptionList = response.exceptions;
                      for (int i = 0; (exceptionList != null) && (i < exceptionList.Length); i++)
                      {
                          System.Console.WriteLine("\nException sequence ID : " + exceptionList[i].id);
                          BusinessService.AgileExceptionType[] exception = exceptionList[i].exception;
                          for (int j = 0; (exception != null) && (j < exception.Length); j++)
                          {
                              System.Console.WriteLine("\nException ID : " + exception[j].exceptionId +
                                  "\nException Message : " + exception[j].message);
                          }
                      }
                      BusinessService.AgileWarningListType[] warningList = response.warnings;
                      for (int i = 0; (warningList != null) && (i < warningList.Length); i++)
                      {
                          System.Console.WriteLine("\nWarning sequence ID : " + warningList[i].id);
                          BusinessService.AgileWarningType[] warning = warningList[i].warning;
                          for (int j = 0; (warning != null) && (j < warning.Length); j++)
                          {
                              System.Console.WriteLine("\nWarning ID : " + warning[j].warningId +
                                  "\nWarning Message : " + warning[j].message);
                          }
                      }
                  }
              }
      
      
              private static void displayGetObjectResponse(ConsoleApplication1.BusinessService.GetObjectResponseType response)
              {
                  String statusCode = response.statusCode.ToString();
                  Console.WriteLine("Status: " + statusCode);
                  if (statusCode.ToUpper().Equals("SUCCESS"))
                  {
                      BusinessService.AgileGetObjectResponse[] responses = response.responses;
                      //Since we are loading on
                      for(int i=0; i<responses.Length;i++) {
                          BusinessService.AgileObjectType agileObject = responses[i].agileObject;
                          BusinessService.ObjectIdentifierType objID = agileObject.objectIdentifier;
                          displayObjectID(objID);
                          System.Xml.XmlElement[] data = agileObject.Any;
                      }
                  } else {
                      BusinessService.AgileExceptionListType[] exceptionList = response.exceptions;
                      for (int i = 0; (exceptionList != null) && (i < exceptionList.Length); i++)
                      {
                          System.Console.WriteLine("Exception sequence ID : " + exceptionList[i].id);
                          BusinessService.AgileExceptionType[] exception = exceptionList[i].exception;
                          for (int j = 0; (exception !=null) && (j< exception.Length); j++)
                          {
                              System.Console.WriteLine("Exception ID : " + exception[j].exceptionId +
                                  "\n Exception Message : " + exception[j].message);
                          }
                      }
                      BusinessService.AgileWarningListType[] warningList = response.warnings;
                      for (int i = 0; (warningList != null) && (i<warningList.Length); i++)
                      {
                          System.Console.WriteLine("Warning sequence ID : " + warningList[i].id);
                          BusinessService.AgileWarningType[] warning = warningList[i].warning;
                          for (int j = 0; (warning !=null) && (j<warning.Length); j++)
                          {
                              System.Console.WriteLine("Warning ID : " + warning[j].warningId +
                                  "\n Warning Message : " + warning[j].message);
                          }
                      }
                  }
              }
      
      
      
      
              private static void displayObjectID(ConsoleApplication1.BusinessService.ObjectIdentifierType objID)
              {
                  System.Console.WriteLine("Class ID : " + objID.classId +
                      " Class Name : " + objID.className+
                      " Object ID : " + objID.objectId+
                      " Object Number : " + objID.objectName);
              }
      
      
              public System.Net.NetworkCredential initialize(string userN, string pass)
              {
                  System.Net.ServicePointManager.Expect100Continue = false;
                  return new System.Net.NetworkCredential(userN, pass);
              }
          }
      }
      

       

      <?xml version="1.0" encoding="utf-8" ?>
      <configuration>
          <configSections>
              <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
                  <section name="ConsoleApplication1.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
              </sectionGroup>
          </configSections>
          <system.serviceModel>
              <bindings />
              <client />
          </system.serviceModel>
          <applicationSettings>
              <ConsoleApplication1.Properties.Settings>
                  <setting name="ConsoleApplication1_BusinessService_BusinessObjectService"
                      serializeAs="String">
                      <value>http://ElmoAgileAPP.elmoil.local:7777/CoreService/services/BusinessObject</value>
                  </setting>
                  <setting name="ConsoleApplication1_TableService_TableService"
                      serializeAs="String">
                      <value>http://ElmoAgileAPP.elmoil.local:7777/CoreService/services/Table</value>
                  </setting>
              </ConsoleApplication1.Properties.Settings>
          </applicationSettings>
      </configuration>
      

       

      Thanks,

      BR