It's all about the answers!

Ask a question

creating requirement in RRC using c#.net into JKE Banking(Requirements Management) - Project Area


chaluvadi sri anil kumar (1323) | asked Oct 01 '12, 7:38 a.m.
 Hi, Im new to c#.net and RRC. My aim is to create a requirement using c#.net. im using the following code:
--------------------------------------------------------------------------------------------------------
XmlDocument newdoc = new XmlDocument();
newdoc.XmlResolver = null;
newdoc.Load(@"C:\Users\anil\Desktop\new.xml");
string content=newdoc.InnerXml; 

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(RequirementCreationFactoryresourceURI);

request.Method = "POST";
request.CookieContainer = cookies;
request.AllowAutoRedirect = false;

if (string.IsNullOrEmpty(login))
{
request.Credentials = CredentialCache.DefaultNetworkCredentials;
}
else
{
request.Credentials = new NetworkCredential(login, password);
}

byte[] byteArray = Encoding.UTF8.GetBytes(content);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
request.Headers.Set("OSLC-Core-Version", "2.0");
request.Accept = "application/rdf+xml";
documentGet.Timeout = 300000;

Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
--------------------------------------------------------------------------------------------------------
But im unable to create the requirement. can anyone explain where did i go wrong?
or if my entire approach is wrong can u guide me posting the code satisfying my requirement.

Note: I had tried the following content in HttpRequester (Add on for mozilla firefox) and it worked fine.
-------------------
 POST https://localhost:9443/rm/requirementFactory?projectURL=https%3A%2F%2Flocalhost%3A9443%2Fjts%2Fprocess%2Fproject-areas%2F_6ddg8AOwEeKnNZwYHFq9wA
<?xml version="1.0" encoding="UTF-8"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:acp="http://jazz.net/ns/acp#" xmlns:calm="http://jazz.net/xmlns/prod/jazz/calm/1.0/" xmlns:dc="http://purl.org/dc/terms/" xmlns:nav="http://jazz.net/ns/rm/navigation#" xmlns:oslc="http://open-services.net/ns/core#" xmlns:oslc_rm="http://open-services.net/ns/rm#" xmlns:public_rm_10="http://www.ibm.com/xmlns/rm/public/1.0/" xmlns:rm="http://www.ibm.com/xmlns/rdm/rdf/" xmlns:rm_property="https://localhost:9443/rm/types/">
  <oslc_rm:Requirement rdf:about="https://localhost:9443/rm/resources/_qDZXsAiREeKvB7mRd0vIRQ">
    <nav:parent rdf:resource="https://localhost:9443/rm/folders/_6ddg8AOwEeKnNZwYHFq9wA"/>
    <dc:description rdf:parseType="Literal"/>
    <acp:accessControl rdf:resource="https://localhost:9443/rm/accessControl/_6ddg8AOwEeKnNZwYHFq9wA"/>
    <dc:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2012-09-27T10:54:06.009Z</dc:modified>
    <rdf:type rdf:resource="http://open-services.net/ns/rm#Requirement"/>
    <oslc:serviceProvider rdf:resource="https://localhost:9443/rm/discovery/_6ddg8AOwEeKnNZwYHFq9wA/services.xml"/>
    <dc:creator rdf:resource="https://localhost:9443/jts/users/chalsak2"/>
    <rm_property:_9SyvUQOwEeKnNZwYHFq9wA rdf:resource="https://localhost:9443/rm/types/_9ArroQOwEeKnNZwYHFq9wA#Text"/>
    <oslc:instanceShape rdf:resource="https://localhost:9443/rm/types/_omyk4QOxEeKnNZwYHFq9wA"/>
    <dc:contributor rdf:resource="https://localhost:9443/jts/users/chalsak2"/>
    <dc:created rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2012-09-27T10:54:06.009Z</dc:created>
    <dc:title rdf:parseType="Literal">New Requirement by anil</dc:title>
    <dc:identifier rdf:datatype="http://www.w3.org/2001/XMLSchema#string">221</dc:identifier>
  </oslc_rm:Requirement>
</rdf:RDF>
-------------------
nex.xml contains the above xml content [not POST <url>]

Accepted answer


permanent link
Gabriel Ruelas (1.1k13) | answered Oct 02 '12, 11:10 a.m.
Looks you are using the right approach. Try by changing :
request.ContentType = "application/x-www-form-urlencoded";
 to
request.ContentType = "application/rdf+xml";
chaluvadi sri anil kumar selected this answer as the correct answer

Comments
chaluvadi sri anil kumar commented Oct 03 '12, 3:04 a.m.

thanks. its done.... 

3 other answers



permanent link
Ravi Kalikate (1617) | answered Apr 01 '15, 2:44 a.m.

Hi Anil,

I am New to RRC and I want to update/modify artifact So can you please tell e what will be the URL for the same.

Actually i want to Update it throught REST.


permanent link
preethi b (112) | answered Dec 12 '19, 6:12 a.m.
hello , i am not able to create the Workitem, there is no error , but the Workitem is not created ,
my code looks like this


using System;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Xml;


namespace JazzConsoleApplication
{
    class Program
    {
        private const string AUTH_MSG_KEY = "X-com-ibm-team-repository-web-auth-msg";
        private const string AUTH_REQUIRED_MSG = "authrequired";
        private const string BASIC_AUTHENTICATION_TYPE = "Basic";

        static void Main(string[] args)
        {
            string repository = "host";
            string username = "username";
            string password = "*****";

            //modify only if proxy requires authentication
            string proxyUsername = "proxyUsername";
            string proxyPassword = "proxyPassword";

            try
            {
                ServicePointManager.Expect100Continue = false;
                ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(Callback);

#if NET_45      // TLS 1.1/1.2 supported in .NET Framework 4.5 and later
                ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
#endif

                SecurityContext context = SecurityContext.CreateSecurityContext(username, password, proxyUsername, proxyPassword);

                Console.WriteLine("Initializing repository...");
                HttpWebResponse initResponse = SendRequest(repository, "/process/project-areas/_1TRdAE6hEeiiuJY3p316gA", context);
                string authMsg = initResponse.Headers[AUTH_MSG_KEY];
                if (authMsg == AUTH_REQUIRED_MSG)
                {
                    Console.WriteLine("Performing Security Check...");
                    HttpWebResponse authResponse = SendRequest(repository, string.Format("/j_security_check?j_username={0}&j_password={1}", username, password), context);
                    authMsg = authResponse.Headers[AUTH_MSG_KEY];
                    if (!string.IsNullOrEmpty(authMsg))
                    {
                        Console.WriteLine("Web Authentication Message: " + authMsg);
                        Exit();
                        return;
                    }


                    //Create WorkItem Task

                    CookieContainer cookies = new CookieContainer();
                    XmlDocument newdoc = new XmlDocument();
                    newdoc.XmlResolver = null;
                    newdoc.Load(@"C:\Users\AMC4KOR\Desktop\New folder\CUrl\new.xml");
                    string content = newdoc.InnerXml;
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(repository + "/oslc/contexts/_1TRdAE6hEeiiuJY3p316gA/workitems/task");
                    request.Method = "POST";
                    request.CookieContainer = cookies;
                    request.AllowAutoRedirect = false;

                    if (string.IsNullOrEmpty(username))
                    {
                        request.Credentials = CredentialCache.DefaultNetworkCredentials;
                    }
                    else
                    {
                        request.Credentials = new NetworkCredential(username, password);
                    }

                    byte[] byteArray = Encoding.UTF8.GetBytes(content);
                    request.ContentType = "application/x-oslc-cm-change-request+xml";
                    request.ContentLength = byteArray.Length;
                    request.Headers.Set("OSLC-Core-Version", "3.0");
                    request.Accept = "text/xml";//"application/rdf+xml";
                    request.Timeout = 300000;

                    Stream dataStream = request.GetRequestStream();
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    dataStream.Close();
                   
                    //request.

                  

                }
                //Create WorkItem Story



                //Console.WriteLine("Getting Project Areas...");
                //SendRequest(repository, "/process/project-areas/_1TRdAE6hEeiiuJY3p316gA", context);
            }

            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            Exit();
        }

        static bool Callback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            //trust all certificates
            return true;
        }

        class SecurityContext
        {
            internal static SecurityContext CreateSecurityContext(string username, string password, string proxyUsername, string proxyPassword)
            {
                NetworkCredential credential = new NetworkCredential(username, password);

                WebHeaderCollection authHeader = new WebHeaderCollection();
                byte[] credBuf = new UTF8Encoding().GetBytes(username + ":" + password);
                authHeader.Add(HttpRequestHeader.Authorization, BASIC_AUTHENTICATION_TYPE + " " + Convert.ToBase64String(credBuf));

                CookieContainer cookie = new CookieContainer();

                NetworkCredential proxyCredential = new NetworkCredential(proxyUsername, proxyPassword);

                return new SecurityContext(credential, authHeader, cookie, proxyCredential);
            }

            internal NetworkCredential Credential;
            internal WebHeaderCollection AuthHeader;
            internal CookieContainer Cookie;
            internal NetworkCredential ProxyCredential;

            SecurityContext(NetworkCredential credential, WebHeaderCollection authHeader, CookieContainer cookie, NetworkCredential proxyCredential)
            {
                this.Credential = credential;
                this.AuthHeader = authHeader;
                this.Cookie = cookie;
                this.ProxyCredential = proxyCredential;
            }
        }

      


        static HttpWebResponse SendRequest(string repository, string service, SecurityContext context)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(repository + service);
            request.AllowAutoRedirect = true;
            request.KeepAlive = true;
            request.Timeout = 480000;
            request.Credentials = context.Credential;
            request.Headers.Add(context.AuthHeader);
            request.CookieContainer = context.Cookie;
            Console.Write("Request Uri:--------------------------------------------------------------------");
            Console.WriteLine(request.RequestUri);
            Console.Write("Request Headers:----------------------------------------------------------------");
            Console.Write(request.Headers);



          
            //request.ContentType = "application/rdf+xml";
            //request.ContentLength = byteArray.Length;
            //request.Headers.Set("OSLC-Core-Version", "3.0");
            //request.Accept = "application/rdf+xml";
            //request.Timeout = 300000;

            //Stream dataStream = request.GetRequestStream();
            //dataStream.Write(byteArray, 0, byteArray.Length);
            //dataStream.Close();

            IWebProxy proxy = WebRequest.DefaultWebProxy;
           
            Uri proxyUri = proxy.GetProxy(request.RequestUri);
            Console.Write("Proxy Uri:----------------------------------------------------------------------");
            Console.WriteLine(proxyUri);
            bool isBypassed = proxy.IsBypassed(request.RequestUri);
            Console.Write("Is Bypassed:--------------------------------------------------------------------");
            Console.WriteLine(isBypassed);

            if (!isBypassed)
                proxy.Credentials = context.ProxyCredential;

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Console.Write("Response Headers:---------------------------------------------------------------");
            Console.Write(response.Headers);
            Console.Write("Response:-----------------------------------------------------------------------");
            Console.WriteLine(ReadResponse(response));
            Console.WriteLine();
            return response;
        }

        static string ReadResponse(HttpWebResponse response)
        {
            StreamReader reader = new StreamReader(response.GetResponseStream());
            return reader.ReadToEnd();
        }

        static void Exit()
        {
            Console.Write("Press any key to exit...");
            Console.ReadKey();
        }
    }
}


Comments
Ralph Schoon commented Dec 12 '19, 6:54 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Why would you paste such code as an answer to a 7 year old question that has been accepted as answered?

Do you expect, someone handles this as a new question? Do you expect anyone to take a day or two off to look at your code import it and experiment with it, especially as there is not any additional information?

permanent link
preethi b (112) | answered Dec 16 '19, 4:38 a.m.
There is no additional information to create the workitem, using c# language ,
Is the above code is applicable for RTC ( rational team concert) ? or only for  the RRC ?
can anyone help resolving it .


Thanks in advance

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.