Calling OTRS Web Services from .NET

In one of the current projects I have to connect to OTRS ticketing back-end.

OTRS is an open-source ticketing application and has a web service interface. I thought that querying the OTRS from NET should be straightforward because there were some examples for PHP that looked easy enough, but I was wrong.

logo[1]

The Symptoms

First of all, the WSDL descriptor for the web service has to be crafted almost by hand, as the generic interface for OTRS allows you to make your own web service interfaces, picking what operations you want to allow and how you should name them. It involved a lot of work for one of the customer IT guys 😉

The second stumble is that the SOAP interface for OTRS methods uses wrapped types, so you have to make the proxy class using SVCUTIL.EXE tool with /wrapped option against the WSDL.

The third problem was that choice types in WSDL is not supported by the WCF default serializer, and you have to "downgrade" it to the old XML serializer calling SVCUTIL.EXE with additional /serializer:XmlSerializer option, too.

Finally, I managed to make a call with the C# proxy client class against OTRS, but my joy was short-lived. The call to OTRS methods always returned null as a result.

The Cause

I fired up Fiddler to investigate the SOAP call. The call was made well and the OTRS responded in kind with a SOAP response filled with data. But, a slight mismatch was detected: the namespace of the response message element was not the same as the request message. Consequently, the NET proxy didn’t deserialize the message to the right type as the namespaces of the data type in NET and the SOAP response didn’t match.

The Solution

In the generated proxy class I looked up the method response data types. In one of them I found this attribute:

[System.ServiceModel.MessageBodyMemberAttribute(Namespace=http://request.contoso.com/operations, Order=0)]

and I changed it into

[System.ServiceModel.MessageBodyMemberAttribute(Namespace=http://response.contoso.com/operations, Order=0)]

Save, build, run and enjoy the correctly-deserialized response from OTRS.

Helpful links

http://stackoverflow.com/questions/7328631/system-invalidoperationexception-xmlserializer-attribute-system-xml-serializat

http://www.primordialcode.com/index.php/2008/10/15/invoking-javaaxis-web-service-net-return-null-issue/

2 thoughts on “Calling OTRS Web Services from .NET”

  1. Hi,

    Did you had any trouble with the web/app config afterwards?

    I have this error after calling :
    The content type application/soap+xml; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)

    GenericTicketConnector_PortTypeClient gtc = new GenericTicketConnector_PortTypeClient(“GenericTicketConnector_Port”);
    SessionCreate sessionCreate = new SessionCreate();
    sessionCreate.Item = “myUser”;
    sessionCreate.ItemElementName = ItemChoiceType8.UserLogin;
    sessionCreate.Password = “password”;
    gtc.SessionCreate(sessionCreate);

    Any idea

    1. Yes, they changed the signature of the web service in later versions, I’m afraid. I ended up using a custom class to serialize SOAP messages to and from OTRS. 🙁

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.