Polarion and C#
Polarion and C#
Hello, is it possible to access to polarion through C# (.NET),
e.g. through WebService or sth like that?
If yes, how?
e.g. through WebService or sth like that?
If yes, how?
-
- Posts: 472
- Joined: Tue Oct 24, 2006 10:27 am
- Location: Polarion Software GmbH, Stuttgart
- Contact:
Re: Polarion and C#
Hi,
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,
Nick
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,
Nick
- Attachments
-
[The extension zip has been deactivated and can no longer be displayed.]
Re: Polarion and C#
IT WORKS !!! ( Partially )
Strange: I get a javax.transaction.RollbackException
at: SessionWebServiceService->endTransaction(false) :
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestNamespace="http://ws.polarion.com/SessionWebService-impl", ResponseNamespace="http://ws.polarion.com/SessionWebService-impl", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public void endTransaction(bool rollback) {
this.Invoke("endTransaction", new object[] {
rollback});
}
Strange: I get a javax.transaction.RollbackException
at: SessionWebServiceService->endTransaction(false) :
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestNamespace="http://ws.polarion.com/SessionWebService-impl", ResponseNamespace="http://ws.polarion.com/SessionWebService-impl", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public void endTransaction(bool rollback) {
this.Invoke("endTransaction", new object[] {
rollback});
}
Re: Polarion and C#
Hi
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.
Ajay
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.
Ajay
Re: Polarion and C#
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.
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#
Hi,
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.
Ajay
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.
Ajay
- Attachments
-
[The extension zip has been deactivated and can no longer be displayed.]
Re: Polarion and C#
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,
Benjamin
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,
Benjamin
Re: Polarion and C#
Hi,
is there somebody who has the files mentioned above?
Unfortunately they are not available anymore.
Many thanks!
Botond
is there somebody who has the files mentioned above?
Unfortunately they are not available anymore.
Many thanks!
Botond
Re: Polarion and C#
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,
Thomas
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,
Thomas
Re: Polarion and C#
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 = "http://ws.polarion.com/session";
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;
message.Headers.Add(header);
}
}
public static string session
{
get
{
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;
wss.SoapExtensionTypes.Add(soapInterceptor);
// 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#
Hi,
Can you please share the working project. Because i'm stuck in Getworkitem function. It's always returning null.
Can you please share the working project. Because i'm stuck in Getworkitem function. It's always returning null.
Re: Polarion and C#
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.
https://polarion.plm.automation.siemens.com/hubfs/Docs/Guides_and_Manuals/How-to-call-Polarion-from-DOT-NET.pdf
The link to the Solution:
https://www.polarion.com/hubfs/Attachments/SampleWebServiceAPI.zip
No native speaker, sorry for my bad English.
Return to “Polarion Application Lifecycle Management (ALM)”
Who is online
Users browsing this forum: No registered users and 8 guests