1

We need to call a SOAP service.

Unfortunately the WSDL generated code does not work as expected because they require MTOM which causes problems we have not been able to resolve. So we are forced to reinvent wheels and I'm trying to figure out the best (or at least a good way) to do this.

The SOAP service will create a response like:

--uuid:d49971de-e2c2-4af4-947d-c0acc0f6ad64
Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml"
Content-Transfer-Encoding: binary
Content-ID: 

<root.message@cxf.apache.org>
    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
        <soap:Body>
            <ns2:listAttachmentsResponse xmlns:ns2="http://ws.praxedo.com/v6/businessEvent">
                <return>
                    <resultCode>0</resultCode>
                    <entities>
                        <entityId>00044</entityId>
                        <name>JohnDoe.pdf</name>
                        <addedOnDevice>false</addedOnDevice>
                        <creationDate>2021-03-17T20:48:36.849+01:00</creationDate>
                        <external>false</external>
                        <id>1103057659_1500033662_C_05126a814b440b8c6efea0d195cbae8f</id>
                        <lastModificationDate>2021-05-04T20:38:42.829+02:00</lastModificationDate>
                        <size>249794</size>
                        <unmodifiable>false</unmodifiable>
                    </entities>
                    <entities>
                        <entityId>00044</entityId>
                        <name>OAY3PD.pdf</name>
                        <addedOnDevice>false</addedOnDevice>
                        <creationDate>2021-03-17T20:48:36.829+01:00</creationDate>
                        <external>false</external>
                        <id>1103057659_1500033662_C_04870c813b0c352bed5213425a946d5c</id>
                        <lastModificationDate>2021-05-04T20:38:42.829+02:00</lastModificationDate>
                        <size>465275</size>
                        <unmodifiable>false</unmodifiable>
                    </entities>
                </return>
            </ns2:listAttachmentsResponse>
        </soap:Body>
    </soap:Envelope>
--uuid:d49971de-e2c2-4af4-947d-c0acc0f6ad64--
  1. Is there a convenient or idiomatic way of extracting the Xml we care about from this response, or do we need to create custom logic to dispose of the boundary and content metadata?

  2. How do I deal with the different namespaces and aliases, and lack thereof, as well as the element named "return"?

I'd like for the result to be a POCO, possibly something like:

public class ListAttachmentsResponse {
    public int ResultCode { get; init; }
    public Attachment[] Attachments
}

public class Attachment {
    // This is the "entityId", we need to keep the leading zeros.
    public string BusinessEventId { get; init; }

    public string FileName { get; init; }
    public bool IsAddedOnDevice { get; init; }
    public DateTime CreationDate { get; init; }
    public bool IsExternal { get; init; }
    public string Id { get; init; }
    public DateTime LastModificationDate { get; init; }
    public int size { get; init; }
    public bool IsUnmodifiable { get; init ;}
}

... but I can be flexible about the structure if something else would be easier to retrieve.

Brian Kessler
  • 2,187
  • 6
  • 28
  • 58
  • There are tools for this. You can have yourself a complete client stub created from the wsdl that the SOAP Service should be providing. See answers to: https://stackoverflow.com/q/2772708/982149 – Fildor Sep 21 '21 at 14:38
  • @Fildor, unfortunately the generated code does not work as expected because they require MTOM which causes problems we have not been able to resolve in a good way. ( See: https://stackoverflow.com/questions/69265927/in-c-how-can-i-create-a-soap-integration-for-the-praxedo-business-event-attach ) ... so we are forced to reinvent wheels and I'm trying to figure out the best (or at least a good way) to do this, – Brian Kessler Sep 21 '21 at 14:53
  • That would be great info to include in the question. – Fildor Sep 21 '21 at 15:03
  • 1
    @Fildor, included. – Brian Kessler Sep 21 '21 at 15:06
  • 1
    Having read that other question: Have you considered contacting praxedo? _They_ should know ... – Fildor Sep 21 '21 at 15:06
  • 1
    @Fildor, their developer support seems very limited, especially for C#. So far, I've learned nothing useful from them. – Brian Kessler Sep 21 '21 at 15:08
  • Welcome in 2021 – Steve B Sep 21 '21 at 16:07

1 Answers1

0

After using Visual Studio's "Paste Special -> Paste Xml as Classes" with some sample data, I was able to get the following method to work:

        private const string EnvelopeClose = "</soap:Envelope>";

        private static listAttachmentsResponse Parse(string responseContent)
        {
            string data = responseContent[responseContent.IndexOf("<soap:Envelope")..];
            int envelopeCloseIndex = data.IndexOf(EnvelopeClose);
            data = data.Substring(0, envelopeCloseIndex) + EnvelopeClose;

            XmlSerializer serializer = new(typeof(ResponseEnvelope));
            ResponseEnvelope result;
            using (StringReader reader = new(data))
            {
                result = (ResponseEnvelope)serializer.Deserialize(reader);
            }
            return result.Body.listAttachmentsResponse;
        }

I think this is very ugly, so I'm open to suggestions for better ways to do this!

Brian Kessler
  • 2,187
  • 6
  • 28
  • 58