Sunday, 5 February 2012

C# with Visual Studio and Rational Team Concert (OSLC revisted) (Part 2)

In Part 1, I showed how to set up a basic visual studio environment which we will now use to create an OSLC client. The client we will create is quite rudimentary and is based on the code in the OSLC workshop (which is itself, java.) 
The code does not do much more then a form-based authentication with RTC and fetches a list of project areas using XPath.  The .NET framework (I am using v. 4) has everything we need to create a connection with RTC, authenticate and query the content. It's just as easy to do with C# as it is in Java and the code, in fact, is quite similar. I am using Visual Studio 2010 and .NET v4 but the code should either work as is, or with some slight modifications, on other versions.

You will need to get the point we finished in Part 1. Once you are there, let's start fresh and close down Visual studio and unzip the following zip file into your sandbox (overwriting along the way.) 

VS/RTC sandbox: C# OSLC

Open up visual studio and immediately go to the RTC "Team Artifacts" window. Go to the sandbox list Right click and select "Set current" to activate and open the solution in Visual Studio. You can go ahead and go to the "Solution Explorer" and delete the default Program.cs and Class1.cs files that the wizard created. You can the add the new .cs files by your the project context menus and Add->Existing Item. You can then add the missing files (OSLCConsumer.cs and HttpUtils.cs) from there.

You can also go ahead and deliver these changes by going to the "Pending Changes" Window, and check-in and deliver all the new changes.

You can to build and run the project at this point by clicking on the "Play" button as per normal Visual Studio usage but you will probably need to modify a few settings namely:

string server = "https://localhost:9443/ccm"; //<-Your RTC server
string url = "https://localhost:9443/ccm/rootservices"; //<- the rootservices URL
string login = "ADMIN";    //<-Your RTC username
string password = "yourpassword";  //<-Your RTC password

Once you have looked over the code and perhaps run it, it demonstrates the following:
  1. How to do form authentication with C#
  2. How to issue OSLC requests using C# 
  3. Use XPath to fetch Project area names (service providers)

If everything is working file, the output window could look like this:
If you need to have more in depth information about how this code functionality works I suggest to take a look at the OSLC workshop as this code sample is loosely based on it. Enjoy!

Next up (part 3)... I will expand on this example, and create an automated build environment for our new code using RTC SCM and automated builds!


  1. Good one.

    I need help in opening up the UI dialog in a Windows application. For ex., I've a button on a Windows form, to open a new Task, Clicking on button I would like to show the Delegated UI Dialog. Is it possible?

    It's quite urgent, any help?


    1. I haven not tried this. Your best bet is to post the question on the forums.

  2. I've posted. But no response since then.

  3. Hello Boris,
    I am trying to get Workitem types of a project area by using this URI but couldn't succeded.

    I used your OSLC code snippet as a starter. I can make it work with my CLM server. But when I try to fetch the URI above like:
    documentGet = (HttpWebRequest)WebRequest.Create(MYNEWURI);
    documentGet.Method = "GET";
    documentGet.CookieContainer = cookies;
    documentGet.Accept = mediatype;
    documentGet.Headers.Set("OSLC-Core-Version", "2.0");
    documentGet.Timeout = 300000;
    response = HttpUtils.sendGetForSecureDocument(server, documentGet, login, password);

    I get HTTP 406 error. 406 means the server does not support the required
    representation. How can I get the workitem type of a project area?

  4. hCan you please help with this error ?
    >> Test: Print out a REST GET response
    - GET https://localhost:9443/ccm/rootservices
    - Accept: application/xml
    - Login: timo
    - Password: timo
    >> GET(1) https://localhost:9443/ccm/rootservices
    >> Response Headers:
    - Transfer-Encoding: chunked
    - Cache-Control: public
    - Content-Type: application/rdf+xml;charset=UTF-8
    - Date: Tue, 06 May 2014 10:46:08 GMT
    - Expires: Tue, 06 May 2014 10:51:08 GMT
    - ETag: "R166zloNsj/qSmirf3Ou9ySgXIc="
    - Server: Apache-Coyote/1.1
    >> HTTP Response Headers:
    - Transfer-Encoding: chunked
    - Cache-Control: public
    - Content-Type: application/rdf+xml;charset=UTF-8
    - Date: Tue, 06 May 2014 10:46:08 GMT
    - Expires: Tue, 06 May 2014 10:51:08 GMT
    - ETag: "R166zloNsj/qSmirf3Ou9ySgXIc="
    - Server: Apache-Coyote/1.1
    The Project Areas for this CCM Server are:
    >> GET(1) https://timo-pcvirtual:9443/ccm/oslc/workitems/catalog
    >> Response Headers:
    - X-com-ibm-team-repository-web-auth-msg: authrequired
    - Content-Length: 1985
    - Cache-Control: private
    - Content-Type: text/html;charset=UTF-8
    - Date: Tue, 06 May 2014 10:46:10 GMT
    - Expires: Thu, 01 Jan 1970 01:00:00 CET
    - Set-Cookie: JazzFormAuth=Form; Path=/ccm
    - Server: Apache-Coyote/1.1
    >> POST https://localhost:9443/ccm/j_security_check
    at System.Net.HttpWebRequest.GetResponse()
    at net.jazz.oslc.utils.HttpUtils.sendGetForSecureDocument(String serverURI, H
    ttpWebRequest request, String login, String password) in C:\Users\timo\Desktop\O
    SCL c#\COSLCConsumer\OSLC Common\OSLC Consumer Common\HttpUtils.cs:line 103
    at net.jazz.oslc.consumer.examples.OSLCConsumer.Main(String[] args) in C:\Use
    rs\timo\Desktop\OSCL c#\COSLCConsumer\OSLC\OSLC Consumer\OSLCConsumer.cs:line 78


  5. I'm glad to see this post. By the way, you may be interested in replica ray bans.

  6. Notwithstanding the pioneer and other team individuals, fruitful team building requires an outsider member in the process - a Facilitator-Coach, an expert with learning and involvement in the field of connected social science team building

  7. Thank you for taking the time to publish this information very useful! Jason Aldean Tickets

  8. We have sell some products of different custom is very useful and very low price please visits this site thanks and please share this post with your friends. Indien visumans√łgning