I am currently trying to send an MTOM post request to a SOAP Service. This is relatively easy to do via SOAPUI5 using some parameter.
This seems to adjusts values within the content-type from this:
Content-Type: application/soap+xml;charset=UTF-8;action="..."
to this:
Content-Type: multipart/related; type="application/xop+xml"; start="<[email protected]>"; start-info="application/soap+xml"; action="..."; boundary="..."
Im trying to recreate this behaviour in a Progress Application with the System.Net. Client. I have tried to look for a parameter inside the System.Net.HttpWebRequest class that I can change to recreate this behaviour, but I couldn't find a way to get to there. Is it possible to send a MTOM request with the System.Net Client?
UPDATE: My Code currently looks like this (Some Values were changed):
USING System.Net.HttpWebRequest FROM ASSEMBLY.
USING System.Net.WebRequest FROM ASSEMBLY.
USING System.Net.HttpWebResponse FROM ASSEMBLY.
USING System.Security.Cryptography.X509Certificates.X509Certificate2 FROM ASSEMBLY.
USING System.Text.Encoding FROM ASSEMBLY.
DEFINE VARIABLE cert AS System.Security.Cryptography.X509Certificates.X509Certificate2 NO-UNDO.
DEFINE VARIABLE req AS System.Net.HttpWebRequest NO-UNDO.
DEFINE VARIABLE uri AS System.Uri NO-UNDO.
DEFINE VARIABLE response AS System.Net.HttpWebResponse NO-UNDO.
DEFINE VARIABLE payLoad AS "System.Byte[]" NO-UNDO.
DEFINE VARIABLE payLoadString AS LONGCHAR NO-UNDO.
DEFINE VARIABLE postReqStream AS System.IO.Stream NO-UNDO.
&scope soaprequest_checkAccountActive " ~
--MIME_Boundary ~~n~
Content-Type: application/xop+xml;charset=UTF-8;type='application/soap+xml';action='checkAccountActive' ~~n~
Content-Transfer-Encoding: 8bit ~~n~
Content-ID: <[email protected]> ~~n~
~~n~
<?xml version='1.0' encoding='utf-8'?> ~~n~
<soap:Envelope ~~n~
xmlns:soap='http://www.w3.org/2003/05/soap-envelope' ~~n~
xmlns:tran='http://www.osci.eu/ws/2014/10/transport' ~~n~
xmlns:oas='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' ~~n~
xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'> ~~n~
<soap:Header xmlns:wsa='http://www.w3.org/2005/08/addressing'> ~~n~
<tran:Author> ~~n~
<tran:Identifier type='xoev' name='&2' category='&3'>&1</tran:Identifier> ~~n~
</tran:Author> ~~n~
<wsa:Action>http://www.xta.de/XTA/CheckAccountActive</wsa:Action> ~~n~
<wsa:To>&4</wsa:To> ~~n~
<wsa:MessageId>&5</wsa:MessageId> ~~n~
<wsa:ReplyTo> ~~n~
<wsa:Address></wsa:Address> ~~n~
</wsa:ReplyTo> ~~n~
</soap:Header> ~~n~
<soap:Body/> ~~n~
</soap:Envelope> ~~n~
~~n~
--MIME_Boundary"
System.Net.ServicePointManager:SecurityProtocol = System.Net.SecurityProtocolType:Tls12.
cert = NEW X509Certificate2("C:\Users\SomeUser\Desktop\SomeCert.pfx", "SomePassword").
ASSIGN
uri = NEW System.Uri ("www.mtomurl.com")
req = CAST (WebRequest:Create (uri), HttpWebRequest).
payLoadString = SUBSTITUTE({&soaprequest_checkAccountActive},
"param1",
"param2",
"param3",
"param4",
"param5").
payLoad = Encoding:UTF8:GetBytes(payLoadString).
ASSIGN
req:Method = 'POST'.
req:ContentType = "multipart/related; type="
+ Quoter ("application/xop+xml")
+ "; " + "start="
+ Quoter ("<[email protected]>")
+ "; start-info="
+ Quoter("application/soap+xml")
+ "; action="
+ Quoter ("http://www.xta.de/XTA/CheckAccountActive")
+ "; boundary="
+ QUOTER("--MIME_Boundary").
req:Headers:Set("MIME-Version", "1.0").
req:KeepAlive = TRUE.
req:UserAgent = "Apache-HttpClient/4.5.5 (Java/16.0.1)".
postReqStream = req:GetRequestStream().
postReqStream:write(payLoad, 0, payLoad:Length).
postReqStream:Close().
req:ClientCertificates:Add(cert).
response = CAST (req:GetResponse (), HttpWebResponse).
MESSAGE response:StatusCode
VIEW-AS ALERT-BOX.
You should probably start by looking at the .NET documentation and code samples. It's often a very simple translation from C# to ABL.