正在进行的 MTOM 请求 OpenEdge

MTOM Request in Progress OpenEdge

提问人:Daniel 提问时间:10/31/2023 最后编辑:Daniel 更新时间:11/16/2023 访问量:108

问:

我目前正在尝试向 SOAP 服务发送 MTOM 发布请求。通过使用某些参数SOAPUI5,这相对容易做到。

这似乎从中调整了内容类型中的值:

内容类型:application/soap+xml;charset=UTF-8;action=“...”

对此:

内容类型:多部分/相关;type=“应用程序/xop+xml”;start=“<[email protected]>”;start-info=“应用程序/soap+xml”;action=“...”;边界=“...”

我试图使用 System.Net 在进度应用程序中重新创建此行为。客户。我试图在System.Net.HttpWebRequest类中查找一个参数,我可以更改该参数以重新创建此行为,但是我找不到到达那里的方法。是否可以使用 System.Net 客户端发送 MTOM 请求?

更新: 我的代码目前如下所示(某些值已更改):

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.
进步 OpenEdge Progress-4GL

评论

0赞 Mike Fechner 10/31/2023
您使用的是哪个 OpenEdge 版本和平台?
0赞 Daniel 10/31/2023
@MikeFechner Progress 12.2 和 Windows 10。

答:

0赞 nwahmaet 10/31/2023 #1

您可能应该从查看 .NET 文档和代码示例开始。这通常是从 C# 到 ABL 的非常简单的翻译。

评论

0赞 Daniel 11/6/2023
我就是这么做的。我尝试像例中那样添加标题。我不断收到HTTP错误400。
0赞 Jensd 11/13/2023
到目前为止,请发布您的代码!