Page 1 of 1

Polarion and C#

Posted: Fri Feb 26, 2010 3:07 pm
by ewiebe
Hello, is it possible to access to polarion through C# (.NET),
e.g. through WebService or sth like that?
If yes, how?

Re: Polarion and C#

Posted: Tue Mar 02, 2010 10:32 am
by NickEntin

here is technical description of some issues with connecting to Polarion WebServices from C#:

Webservices use an implicit (not defined in WSDL) SOAP header to indicate that a request is coming from the same client.
The header is sent by the server with each request and should be returned by the client with each request.
I have attached a simple example that demonstrates the session handling.
The important part is the SessionExtension.cs which is registered in the app.config and takes care of the session handling.

Another potential issue is the code generation:
If web references are used, .net will generate a different Project and User type for TrackerWebService and ProjectWebService.
If you want to create a Work Item with that code you will have to map between the different types.
(Actually mapping the types is not difficult as for modifying Work Items only the URI of projects/users matters).
The example includes code generated with the command line tool that avoids this problem and instructions how to regenerate the code.
See attachment for the example of code...

Best regards,

Re: Polarion and C#

Posted: Tue Mar 02, 2010 10:46 am
by ewiebe
Many THANKS Nick !!!

Re: Polarion and C#

Posted: Tue Mar 02, 2010 11:13 am
by ewiebe
IT WORKS !!! ( Partially )

Strange: I get a javax.transaction.RollbackException
at: SessionWebServiceService->endTransaction(false) :

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestNamespace="", ResponseNamespace="", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public void endTransaction(bool rollback) {
this.Invoke("endTransaction", new object[] {

Re: Polarion and C#

Posted: Tue Mar 02, 2010 12:20 pm
by ajaywazir
Looks good in console mode.
However, I am having trouble in getting project data in a WinForm application.
I just copied and pasted the code into a simple Winform application (after making it work in a console application).
While I can login successfully, (no exception is thrown),
I can retrieve list of users,
but I cannot get project details.

Any suggestions.

Re: Polarion and C#

Posted: Tue Mar 02, 2010 12:28 pm
by ewiebe
IT WORKS completely (in console mode) !!!
Thank you very much!

The problem was that I had no access to the underlying subversion. After my administrator gave me SVN access, everything woks fine.

Re: Polarion and C#

Posted: Wed Mar 03, 2010 4:36 am
by ajaywazir
Further to my last post about WinForm problem.
Here is the zipped project. (I have used Async delegates to fire each method, as modification from my last post)
Neither approach works.
Hope someone can help me.

Re: Polarion and C#

Posted: Wed Mar 03, 2010 3:19 pm
by engeleb
Hello Ajay,
you also have to copy the app.config from PoarionWS into your project, otherwise SessionExtension won't be used and the server won't be able to identify you ass the same client on subsequent calls.
Regarding the list of users: I guess you are also not able to get the user details, users should be unresolvable and all properties except uri should be empty.

Best Regards,

Re: Polarion and C#

Posted: Fri Nov 22, 2013 9:41 pm
by ABotond
is there somebody who has the files mentioned above?
Unfortunately they are not available anymore.

Many thanks!


Re: Polarion and C#

Posted: Mon Jul 20, 2015 11:55 am
by ibb
Hi all,

I would be interested in working with C' vs. the Polarion Web Services, too.

Would it be possible to post the code (solution) here again?

Thanks in advance,

Re: Polarion and C#

Posted: Thu Aug 13, 2015 10:21 am
by Endios
Here is my working C# code. The SOAP extension must be done before the login (see main). You must import the WebServices before you run the main and name them "Session","Tracker" and "Project" or change the main accordingly.

Code: Select all

using System;
using System.Diagnostics;
using System.Reflection;
using System.Security.Permissions;
using System.Web.Services.Configuration;
using System.Web.Services.Protocols;
using System.Xml;

namespace PolarionConnector
  internal class SessionExtension : System.Web.Services.Protocols.SoapExtension
    private const string session_ns = "";
    private const string session_name = "sessionID";

    private static string sessionId;

    /// <summary>
    /// Overrides process message function
    /// </summary>
    /// <param name="message"></param>
    public override void ProcessMessage(System.Web.Services.Protocols.SoapMessage message)
      if (message.Stage == System.Web.Services.Protocols.SoapMessageStage.AfterDeserialize)
        //if after deserialisation
        foreach (SoapUnknownHeader header in message.Headers)
          if (header.Element.LocalName == session_name && header.Element.NamespaceURI == session_ns)
            sessionId = header.Element.InnerText;

      else if (message.Stage == System.Web.Services.Protocols.SoapMessageStage.BeforeSerialize && sessionId != null)
        //if before deserialisation
        SoapUnknownHeader header = new SoapUnknownHeader();
        XmlDocument doc = new XmlDocument();
        header.Element = doc.CreateElement("session", session_name, session_ns);
        header.Element.InnerText = sessionId;
    public static string session
        return sessionId;

    public override object GetInitializer(Type serviceType)
      return null;

    public override object GetInitializer(System.Web.Services.Protocols.LogicalMethodInfo methodInfo, System.Web.Services.Protocols.SoapExtensionAttribute attribute)
      return null;

    public override void Initialize(object initializer)

  internal static class RegisterSOAP
    /// <summary> 
    /// Programatically registers a <see cref="SoapExtension"/> at runtime with the specified 
    /// <see cref="SoapExtensionTypeElement.Priority"/> and <see cref="SoapExtensionTypeElement.Group"/> settings. 
    /// </summary> 
    /// <param name="type">The <see cref="Type"/> of the <see cref="SoapExtension"/> to register.</param> 
    /// <param name="priority"> 
    /// A value that indicates the relative order in which this SOAP extension runs when multiple SOAP extensions are 
    /// specified. Within each group the priority attribute distinguishes the overall relative priority of the SOAP   
    /// extension. A lower priority number indicates a higher priority for the SOAP extension. The lowest possible   
    /// value for the priority attribute is 1. 
    /// </param> 
    /// <param name="group"> 
    /// The relative priority group (e.g. Low or High) in which this SOAP extension runs when multiple SOAP extensions   
    /// are configured to run. 
    /// </param> 
    [ReflectionPermission(SecurityAction.Demand, Unrestricted = true)]
    public static void RegisterSoapExtension(Type type, int priority, PriorityGroup group)
      if (!type.IsSubclassOf(typeof(SoapExtension)))
        throw new ArgumentException("Type must be derived from SoapException.", "type");
      if (priority < 1)
        throw new ArgumentOutOfRangeException("priority", priority, "Priority must be greater or equal to 1.");
      // get the current web services settings... 
      WebServicesSection wss = WebServicesSection.Current;

      // set SoapExtensionTypes collection to read/write... 
      FieldInfo readOnlyField = typeof(System.Configuration.ConfigurationElementCollection).GetField("bReadOnly", BindingFlags.NonPublic | BindingFlags.Instance);
      readOnlyField.SetValue(wss.SoapExtensionTypes, false);

      // inject SoapExtension... 
      SoapExtensionTypeElement soapInterceptor = new SoapExtensionTypeElement();
      soapInterceptor.Type = type;
      soapInterceptor.Priority = priority;
      soapInterceptor.Group = group;

      // set SoapExtensionTypes collection back to readonly and clear modified flags... 
      MethodInfo resetModifiedMethod = typeof(System.Configuration.ConfigurationElement).GetMethod("ResetModified", BindingFlags.NonPublic | BindingFlags.Instance);
      resetModifiedMethod.Invoke(wss.SoapExtensionTypes, null);
      MethodInfo setReadOnlyMethod = typeof(System.Configuration.ConfigurationElement).GetMethod("SetReadOnly", BindingFlags.NonPublic | BindingFlags.Instance);
      setReadOnlyMethod.Invoke(wss.SoapExtensionTypes, null);

  class Program
    static void Main(string[] args)
      RegisterSOAP.RegisterSoapExtension(typeof(SessionExtension), 1, PriorityGroup.High); // This bit inserts the SOAP extended Header
      System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; //this is optional and disabled the Certificate check, remove this line if your security is OK
      Session.SessionWebServiceService session = new Session.SessionWebServiceService();
      Tracker.TrackerWebServiceService tracker = new Tracker.TrackerWebServiceService();
      Project.ProjectWebServiceService project = new Project.ProjectWebServiceService();
      session.logIn("username", "password");
      session.hasSubject(); //<< if this does not fail, the session is valid and can be used
      var pr = project.getProject("<HERE GOES RPOJECT NAME>"); //pr holds the recieved project

Re: Polarion and C#

Posted: Tue Jul 31, 2018 6:26 am
by jay0909

Can you please share the working project. Because i'm stuck in Getworkitem function. It's always returning null.

Re: Polarion and C#

Posted: Wed Aug 01, 2018 3:35 pm
by rpn
ibb wrote:Would it be possible to post the code (solution) here again?

The original Solution is still online, the link to it is hiding in the following pdf-file.

The link to the Solution: