It's all about the answers!

Ask a question

Add comment to work item using API


ronen r (2152) | asked Oct 12 '09, 11:42 a.m.
I'm trying to add new comment to a work item using c#
and I can't make it work.
I get the exception:
The remote server returned an error: (400) Bad Reques

(I'm trying to aviod using CURL)
my code is:

//set URL
HttpWebRequest request =
WebRequest.Create(new Uri("https://192.168.16.14:9443/jazz/oslc/workitems/_LD0j4K2vEd6wr5OgrMF4rQ/rtc_cm:comments")) as HttpWebRequest;

//authentication
request.Referer = this.refererLogIn;
request.CookieContainer = this.cookieContainer;

//Request parameters
request.ContentType = "application/x-oslc-cm-change-request+xml";
request.Accept = "text/xml";
request.Method = "POST";

//Get the XML file to byte
byte[] bytes;
using (FileStream fsSource = new FileStream(@"C:\xmlCommant.xml",
FileMode.Open, FileAccess.Read))
{
// Read the source file into a byte array.
bytes = new byte[fsSource.Length];
int numBytesToRead = (int)fsSource.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = fsSource.Read(bytes, numBytesRead, numBytesToRead);

// Break when the end of the file is reached.
if (n == 0)
break;

numBytesRead += n;
numBytesToRead -= n;
}
}
request.ContentLength = bytes.Length;

//Write to stream
Stream newStream = request.GetRequestStream();
newStream.Write(bytes, 0, bytes.Length);
newStream.Close();

//Error is thrown
HttpWebResponse response = request.GetResponse() as HttpWebResponse;


thanks for any help

3 answers



permanent link
Patrick Streule (4.9k21) | answered Oct 12 '09, 2:35 p.m.
JAZZ DEVELOPER
I'm trying to add new comment to a work item using c#
and I can't make it work.
I get the exception:
The remote server returned an error: (400) Bad Reques
(I'm trying to aviod using CURL)
my code is:

400 Bad Request usually contains an error element in the requested format
(XML in your case) that describes the problem in more detail.
Can you check if there is such an error description?

--
Regards,
Patrick
Jazz Work Item Team

permanent link
ronen r (2152) | answered Oct 13 '09, 4:46 a.m.
I'm trying to add new comment to a work item using c#
and I can't make it work.
I get the exception:
The remote server returned an error: (400) Bad Reques
(I'm trying to aviod using CURL)
my code is:

400 Bad Request usually contains an error element in the requested format
(XML in your case) that describes the problem in more detail.
Can you check if there is such an error description?

--
Regards,
Patrick
Jazz Work Item Team

Thanks for your help Patrick
I get the error:

Malformed XML: The prefix "rtc_cm" for element "rtc_cm:Comment" is not bound.

my xml file is(I replace the first '>' char to '
[rtc_cm:Comment rdf:resource="https://192.168.16.14:9443/jazz/oslc/workitems/10/rtc_cm:comments/0">
dc:created>
2009-10-12T12:27:24.170Z
[/dc:created>
[dc:creator rdf:resource="https://192.168.16.14:9443/jazz/oslc/users/_tj6fYK2lEd6wr5OgrMF4rQ" />
[dc:description>
OK
[/dc:description>
[/rtc_cm:Comment>


Regards,
Ronen

permanent link
ronen r (2152) | answered Oct 13 '09, 5:58 a.m.
I found my answer:
the XML file need to get the description of all parameters like "rtc_cm".
I enterd to one of the comments in my work item and copy the parameters.
my xml file need to change to:

[?xml version="1.0" encoding="UTF-8" ?>
[rtc_cm:Comment rdf:resource="https://192.168.16.14:9443/jazz/oslc/workitems/821/rtc_cm:comments/6" xmlns:rtc_cm="http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/"
xmlns:oslc_disc="http://open-services.net/xmlns/discovery/1.0/"
xmlns:dc="http://purl.org/dc/terms/"
xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"
xmlns:jp="http://jazz.net/xmlns/prod/jazz/presentation/1.0/"
xmlns:jd="http://jazz.net/xmlns/prod/jazz/discovery/1.0/"
xmlns:oslc_cm="http://open-services.net/xmlns/cm/1.0/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:calm="http://jazz.net/xmlns/prod/jazz/calm/1.0/">
[dc:created>2009-10-11T13:57:47.973Z[/dc:created>
[dc:creator rdf:resource="https://192.168.16.14:9443/jazz/oslc/users/_tj6fYK2lEd6wr5OgrMF4rQ" />
[dc:description>OK[/dc:description>
[/rtc_cm:Comment>

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.