Book a Demo

Author Topic: Access to polarion from EA Addin  (Read 3162 times)

Eugen Wiebe

  • EA User
  • **
  • Posts: 20
  • Karma: +0/-0
    • View Profile
Access to polarion from EA Addin
« on: March 05, 2010, 03:32:55 am »
Hello, I have created a C# plug in for EA (version 7.5). Works fine!
Then I have created a library which gives access to polarion ALM server (created through WSDL).

Problem: when I access and query polarion items from a stand-alone-application: IT WORKS.

When I access and query polarion items from the EA Addin, I get the same number of polarion items, but they are empty (null).

Do you have an idea?
I have tried several possibilities (console app, WinForms app...) but its always the same. When calling from an EA Addin, it does not work.

 :-? :-?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Access to polarion from EA Addin
« Reply #1 on: March 05, 2010, 01:44:16 pm »
Eugen,

That seems strange, I've never had such an issue before, and I always create a standalone application together with my addin (for testing purposes).
I did notice however that Visual Studio makes a difference in the target .NET framework depending on whether you create a library (dll) or a standalone application project.
Could it have something to do with that?

Geert

Eugen Wiebe

  • EA User
  • **
  • Posts: 20
  • Karma: +0/-0
    • View Profile
Re: Access to polarion from EA Addin
« Reply #2 on: March 05, 2010, 09:08:39 pm »
I think, I have the solution:

1. The important thing is that you use special settings:
----------------------------------------------------------------
In you app.config these items must be:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <webServices>
      <soapExtensionTypes>
        <add type="PolarionWS.SessionExtension,PolarionWS"
        priority="1"
        group="High" />
      </soapExtensionTypes>
    </webServices>
  </system.web>
</configuration>



2. And there must be a special class in your addin (sub)assembly :
--------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Services.Protocols;
using System.Xml;

namespace PolarionWS
{
    /// <summary>
    /// Class for extending SoapExtension class
    /// </summary>
    public 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);
            }
        }


        /// <summary>
        /// Gets session
        /// </summary>
        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)
        {
        }
    }
}


and 3. The application which uses this library must use these configs
-------------------------------------------------------------------------------
I have created a file EA.exe.config and filled with same content as app.config (see above) and added to installation directory of EA (d:\programme\Sparx\EA)
So the application will use these settings when using webservices