How to connect .NET application to OTRS web service

Since the official WSDL file had published on GitHub doesn’t work with .NET applications, I try to found how to fix its. Thanks to Andrey Antipov who helps me found some mistakes and colleagues from OTRS forum.

Connection from .NET application to OTRS web service

In my case OTRS was installed on Linux platform and NTLM authentication with Windows Active Directory is used. So, we should find proper binding.  basicHttpBinding is not suitable, since it support SOAP 1.1 version, but OTRS support OTRS 1.2. Properly working App.config to connect .NET (in my case C#) application to OTRS:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="GenericTicketConnector_Service" />
            </basicHttpBinding>
          <customBinding>
            <binding name="GenericTicketConnector_Service">
              <textMessageEncoding messageVersion="Soap12" writeEncoding="utf-8" />
              <httpTransport authenticationScheme="Ntlm" proxyAuthenticationScheme="Ntlm" decompressionEnabled="false" realm=""/>
            </binding>
          </customBinding>
        </bindings>
      <behaviors>
        <endpointBehaviors>
          <behavior name="EndpointBehavior">
            <clientCredentials>
              <windows allowedImpersonationLevel="Impersonation" />
            </clientCredentials>
          </behavior>
        </endpointBehaviors>
      </behaviors>
        <client>
            <endpoint address="http://s-otrs-1-vm.ridan.local/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector"
                behaviorConfiguration="EndpointBehavior"
                binding="customBinding" bindingConfiguration="GenericTicketConnector_Service"
                contract="OTRSClient.OTRSServiceReference.GenericTicketConnector_Interface"
                name="GenericTicketConnector_endPoint"/>
        </client>
    </system.serviceModel>
</configuration>

Kerberos also work normally after small App.Config correction. Unfortunately, I don’t remember exactly right one, and now I have no test OTRS installation with Kerberos support.

Instead of using <behaviors> tag in app.config you can use C# code:

OTRSClient.OTRSServiceReference.GenericTicketConnector_InterfaceClient _otrs = new OTRSClient.OTRSServiceReference.GenericTicketConnector_InterfaceClient("GenericTicketConnector_endPoint");
_otrs.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

Missed namespace in Reference.cs generation from WSDL file

When we use SVCUTIL to generate Reference.cs, it creates wrong code, missing needed namespace. So, to get working *.cs file we should replace in generated *.cs file all phrase Namespace=»» to Namespace=»http://www.otrs.org/TicketConnector/». To easy *.cs file generation I wrote small *.cmd file:

"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\SvcUtil.exe" /out:OTRS.cs /wrapped /serializer:XmlSerializer /n:"*,OTRSClient.OTRSServiceReference" GenericTicketConnectorSOAP.wsdl
powershell -Command "(gc OTRS.cs) -replace 'Namespace=\"\"', 'Namespace=\"http://www.otrs.org/TicketConnector/\"' | Out-File OTRS.cs -Encoding ASCII"

Missed some properties in WSDL file

Previous approach fixes one of the problem with WSDL file. The second one, that in WSDL described only few of web services properties described in developer documentation. So, when you generate *.cs file, some of class properties are missed.

When SOAP formatter gets SOAP responses and try to deserialize its, when it founds one of such missed property, it stops processing properties in response at all. So, properties before the missed element is processed correctly and filled with right values, but starting missed property and further properties gets null value.

For SOAP formatter also critical the sequence (order) of properties. So, if in SOAP response exists some properties which are missed in WSDL or sequence is differ than in SOAP response, we’ll get null value for such properties in code.

The main problem with properties and sequence, that there is no full information in OTRS documentation about this important things for .NET developers. As far as I understand, for Perl and some other languages is not so critical to follow right sequence and have all properties described in WSDL file. For .NET it’s critical.

So, I tried to make proper WSDL file, but still I have problems with some properties. I add missed property in sections marked as «Andrey Fedorov»: OTRS. I’ll update this file as soon as I find some mistakes. This WSDL file work normally with OTRS 3.3.

Опубликовать в Facebook
Опубликовать в Google Plus
Опубликовать в LiveJournal
Опубликовать в Мой Мир
Опубликовать в Одноклассники
Опубликовать в Яндекс
Запись опубликована в рубрике IT tools с метками , , , , , . Добавьте в закладки постоянную ссылку.