3

I am trying to connect to a third-party service described as a .wsdl file. I can't provide the whole file because it's too long, but essential parts are:

<wsdl:port name="ec2HttpSoap12Endpoint" binding="tns:ec2Soap12Binding">
  <soap12:address location="<service url>.ec2HttpSoap12Endpoint/"/>
</wsdl:port>

<wsdl:binding name="ec2Soap12Binding" type="tns:ec2PortType">
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
  <wsdl:operation name="someOperation">
    <soap12:operation soapAction="urn:someOperation" style="document"/>
    <wsdl:input>
      <soap12:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
      <soap12:body use="literal"/>
    </wsdl:output>
  </wsdl:operation>
  ...
</wsdl:binding>

My code is simple:

ec2PortTypeClient client = new ec2PortTypeClient("ec2HttpSoap12Endpoint", "<service url>");
var response = ePortConnect.someOperation(...).Result.@return;

But I get an exception:

ProtocolException: The content type multipart/related; boundary="MIMEBoundary_f9ac1ac9023b2de2dbb6e3f07d0952ff0bbdfdd7433cd9ec"; type="application/xop+xml"; start="<0.e9ac1ac9023b2de2dbb6e3f07d0952ff0bbdfdd7433cd9ec@apache.org>"; start-info="application/soap+xml"; action="urn:someOperation" of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). ... The first 1024 bytes of the response were:

And then a totally normal response from the server!

Looks like the definition is normal, but response type should be set to XOP, or my C# code is wrong. The server is responding normally, but response isn't being parsed due to type mismatch. What am I doing wrong?

Supplier claims that .wsdl is correct and I believe them. But what can possibly be wrong in my two-line code?

Link to a complete .wsdl file.

AndrewR
  • 592
  • 2
  • 6
  • 20
  • Take a look at this https://www.ibm.com/support/knowledgecenter/en/SSGMCP_5.3.0/com.ibm.cics.ts.webservices.doc/mtomxop/dfhws_attachments_and_SOAP.html (basic description of what xop+xml is), this https://en.wikipedia.org/wiki/XML-binary_Optimized_Packaging (more on xop+xml), this https://stackoverflow.com/questions/10496186/error-consuming-webservice-content-type-application-xopxml-does-not-match-ex (possible solution in aswer there) and this https://github.com/dotnet/wcf/issues/2919 (another possibly analagous issue) – tolanj Sep 30 '19 at 09:48

1 Answers1

1

Try Mtom instead of text to encode SOAP messages.

Config: <binding messageEncoding="Mtom"> Code: binding.MessageEncoding = WSMessageEncoding.Mtom;
Sreeram Nair
  • 2,369
  • 12
  • 27