Reputation: 19
I am consuming a SOAP webservice from our ticket system OTRS. So the Webservice is not really under my control.
The request works just fine, but i am never getting an answer in my Code. The answer is always null. (var response = client.SessionCreate(session);
)
The strange thing is, that wireshark and the webservice console of that ticket system are saying that i should receive a valid answer.
Since i am very new to this webservice stuff so i have absolutely no idea where to start in this case. So here is a description of that i did. Any suggestion is really appreciated.
First i created a normal C# project and added the WSDL file which can be found only on the GitHub site website of the OTRS project. I added it as a Service Reference and than added my C# code which looks like this.
// For Debug System.Net.ServicePointManager.Expect100Continue = false; Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");
try
{
OTRS.OTRS_Error err = new OTRS.OTRS_Error();
OTRS.GenericTicketConnector_PortTypeClient client = new OTRS.GenericTicketConnector_PortTypeClient("GenericTicketConnector_Port");
OTRS.SessionCreate session = new OTRS.SessionCreate();
session.Item = "someUserNameGoesHere";
session.ItemElementName = OTRS.ItemChoiceType8.UserLogin;
session.Password = "SomePasswordGoesHere";
var response = client.SessionCreate(session);
Console.WriteLine(response.SessionID);
Console.WriteLine(response.Error);
}
catch (Exception exep)
{
Console.WriteLine(exep.Message);
Console.WriteLine(exep.InnerException);
}
finally
{
Console.ReadLine();
}
Incoming message at serverside
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://www.otrs.org/TicketConnector/SessionCreate</a:Action>
<a:MessageID>urn:uuid:14750529-3de2-4618-8db4-8ac18b681c18</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">http://SomeServer/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector</a:To>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SessionCreate xmlns="http://www.otrs.org/TicketConnector/">
<UserLogin xmlns="">someUserName</UserLogin>
<Password xmlns="">somePassword</Password>
</SessionCreate>
</s:Body>
Outgoing message at serverside
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding"
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<SessionCreateResponse xmlns="http://www.otrs.org/TicketConnector/">
<SessionID>SomeSessionID</SessionID>
</SessionCreateResponse>
</soap:Body>
</soap:Envelope>
Wireshark HTTP/XML package going from the server to my client
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding"
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<SessionCreateResponse xmlns="http://www.otrs.org/TicketConnector/">
<SessionID>SomeSessionID</SessionID>
</SessionCreateResponse>
</soap:Body>
</soap:Envelope>
Refernce.cs https://gist.github.com/HansVader/1ba3847d918ee15ef16703c8ada6c9bf
WSDL https://gist.github.com/HansVader/dd849e49f4a1584397cd21b0e430b301
I currently only need the SessionnCreate and TicketUpdate function. The other operations are irrelevant at this point in time. Please let me know if you need any other informations.
Update:
Here are the traces from the trace tool like yildizm85 suggested in the comments:
I think it is also worth noting that i created the refernce.cs
by myself with the svcutil
tool because i had a problem with the IsWrapped. Have a look at this question and answer:
XmlSerializer attribute not valid in Web Service using WCF
Upvotes: 0
Views: 1896
Reputation: 21
The WSDL does not define elementFormDefault:
<xsd:schema targetNamespace="http://www.otrs.org/TicketConnector/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
Since unqualified is default, this causes every property to be decorated with Form=System.Xml.Schema.XmlSchemaForm.Unqualified in the generated reference file.
But, since there is a default namespace specified for each complex object, the XML serializer will not process the unqualified properties.
The solution
Change the schema element to:
<xsd:schema targetNamespace="http://www.otrs.org/TicketConnector/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
Also, for some of the properties, the order is wrong, so they need to be changed to (for example TickerCreateResponse):
<xsd:element name="TicketCreateResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="ArticleID" type="xsd:positiveInteger"/>
<xsd:element maxOccurs="1" minOccurs="1" name="TicketID" type="xsd:positiveInteger"/>
<xsd:element minOccurs="1" name="TicketNumber" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="Error" type="tns:OTRS_Error"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
After these changes, create the proxy using svcutil:
svcutil.exe /serializer:XmlSerializer GenericTicketConnectorSOAP.wsdl /o:OtrsConnector.cs /wrapped /n:*,otrs
And using the config:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="GenericTicketConnector_Binding">
<textMessageEncoding messageVersion="Soap12" writeEncoding="utf-8" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector"
binding="customBinding" bindingConfiguration="GenericTicketConnector_Binding"
contract="otrs.GenericTicketConnector_PortType" name="GenericTicketConnector_Port" />
</client>
</system.serviceModel>
It should work after that, at least it did for me.
Hope it works for you as well!
Upvotes: 1