Hey fellow Cpians,
i have a problem with a connection to a Server with the REST.API. The code posted below is EXAMPLECODE.
As soon as i reach the point of client.DownloadData(...) it fails the Handshake producing the error "The connection was closed. Unexpected error while sending...".
The inner Exception is "Error on handshake, unexpected package format".
I don'T have any clue what the problem is since this is my first try with REST and C#.
BTW the URI String : "https://servername:8080/cb/rest/user/myuser/items/page/1?role=assigned to&status=Unresolved&pagesize=50&onlyDirect=False";
Additionally, when i put the URI into the firefox i recieve data, but the program crashes. So i guess this is a C# problem?
Thanks :)
EDIT:
I tried connecting without https:// and instead using only http://, this actually works but i don'T get any data back (as i expected). So is this some kind of SSL issue?
Finally:
Thanks Sacha for your info, i'll keep that in mind for the future, for now i just tried again with http:// in the app. If i replace downloadData with downloadString it works. Now i have to get the "DataDownload" correct and it'll be fine.
What I have tried:
static void Main(string[] args)
{
ProgramArguments arguments = parseArguments(args);
if (arguments.Debug)
{
printOutArguments(arguments);
}
int pageNum = 1;
bool ready = false;
WebClient client = getWebClient(arguments);
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ResultObject));
List<WorkItem> workItems = new List<WorkItem>();
while (!ready)
{
StringBuilder urlBuilder = new StringBuilder(500);
urlBuilder.Append(arguments.Endpoint).Append("/cb/rest/user/").Append(arguments.UserName).
Append("/items/page/").Append(pageNum).Append("?").Append("role=assigned to").
Append("&status=Unresolved").Append("&pagesize=").Append(arguments.PageSize).Append("&onlyDirect=").Append(arguments.OnlyDirect);
try
{
using (MemoryStream input = new MemoryStream(client.DownloadData(urlBuilder.ToString())))
{
ResultObject resultObject = (ResultObject)serializer.ReadObject(input);
if (resultObject.items != null)
{
foreach (Item item in resultObject.items)
{
IItemConverter converter = getItemConverter(arguments);
workItems.Add(converter.Convert(item));
}
}
ready = (pageNum * arguments.PageSize) > resultObject.total;
pageNum++;
}
}
catch (Exception e)
{
if (arguments.Debug)
{
Console.WriteLine("Error: {0}", e.ToString());
}
ready = true;
}
}
if (arguments.Debug)
{
Console.WriteLine(workItems.Count + " issue fetched from codeBeamer!");
}
StreamWriter writer = null;
try
{
writer = getOutputWriter(arguments);
OutputProviderFactory.GetProvider(arguments).GenerateOutput(workItems, writer);
}
finally
{
if (writer != null)
{
writer.Close();
}
}
}