[progress Communities] [progress Openedge Abl] Forum Post: Re: How To Get Soap-reponse To...

Status
Not open for further replies.
S

Samuel ETTERLEN

Guest
Hi there, here an example for consuming a Multipart SOAP Webservice (QUERY and RESPONSE): block-level on error undo, throw. using OpenEdge.Core.*. using OpenEdge.Net.HTTP.*. using OpenEdge.Net.HTTP.IHttpRequest. using OpenEdge.Net.HTTP.IHttpResponse. using OpenEdge.Net.HTTP.IHttpResponse. using OpenEdge.Net.HTTP.Lib.ClientLibraryBuilder. using OpenEdge.Net.MessagePart. using OpenEdge.Net.MultipartEntity. define input parameter cFilePath as character no-undo. define input parameter cFileName as character no-undo. define output parameter FileId as character no-undo. define variable oRequest as IHttpRequest no-undo. define variable oResponse as IHttpResponse no-undo. define variable oRequestBody as longchar no-undo. define variable oResponseMemptrEntity as OpenEdge.Core.Memptr no-undo. define variable oResponseMultipartEntity as OpenEdge.Net.MultipartEntity no-undo. define variable oMessagePart as OpenEdge.Net.MessagePart no-undo. define variable oByteBucket as OpenEdge.Core.ByteBucket no-undo. define variable oBody as OpenEdge.Core.ByteBucket no-undo. define variable oFile as OpenEdge.Core.ByteBucket no-undo. define variable oPart as OpenEdge.Net.MessagePart no-undo. define variable oFilePart as OpenEdge.Net.MessagePart no-undo. define variable oHeader as OpenEdge.Net.HTTP.HttpHeaderBuilder no-undo. define variable oEntity as OpenEdge.Net.MultipartEntity no-undo. define variable mData as memptr no-undo. define variable CRLF as character initial "~r~n" no-undo. define variable cResponse as longchar no-undo. define variable ErrorCode as character no-undo. define variable ErrorDescription as character no-undo. define variable cLength as integer no-undo. define variable hXDoc as handle no-undo. define variable lcUTF-8 as longchar no-undo. define variable cSoapHeader as longchar no-undo. define temp-table ttBody no-undo xml-node-name "Body" field dummyField as character xml-node-name "dummyField". define temp-table ttUploadResponse no-undo xml-node-name "UploadResponse" field ErrorCode as character xml-node-name "ErrorCode" field ErrorDescription as character xml-node-name "ErrorDescription" field FileId as character xml-node-name "FileId". define dataset Envelope for ttBody, ttUploadResponse. define variable vGUID as character no-undo. assign vGUID = guid. /* Erzeugt das SOAP-QUERY für UploadFile */ oRequestBody = ' ' + CRLF + ' ' + CRLF + ' ' + string(cLength) + ' ' + CRLF + ' ' + cFileName + ' ' + CRLF + ' ' + CRLF + ' ' + CRLF + ' ' + CRLF + ' ' + ' ' + ' ' + CRLF + ' ' + CRLF + ' ' + CRLF + ' '. oBody = ByteBucket:Instance(). oBody:putString(oRequestBody). oBody:putString(CRLF). assign oEntity = new MultipartEntity() oEntity:Boundary = vGUID oPart = new MessagePart('application/xop+xml; charset=UTF-8; type="text/xml"':u, oBody). oPart:Headers:put(HttpHeaderBuilder:Build('Content-Transfer-Encoding':u) :Value("8Bit") :Header). oPart:Headers:put(HttpHeaderBuilder:Build('Content-ID':u) :Value(" ") :Header). /* Das SOAP-HEADER ist das erste Part des QUERY */ oEntity:AddPart(oPart). oFile = ByteBucket:Instance(). set-size(mData) = 0. copy-lob file cFilePath + cFileName to mData. oFile:putBytes(mData). oFilePart = new MessagePart('application/base64; name=file64.pdf':u, oFile). oFilePart:Headers:put(HttpHeaderBuilder:Build('Content-Transfer-Encoding':u) :Value("binary") :Header). oFilePart:Headers:put(HttpHeaderBuilder:Build('Content-ID':u) :Value(" ") :Header). oFilePart:Headers:put(HttpHeaderBuilder:Build('Content-Disposition':u) :Value('attachment; name="file64.pdf"; filename="file64.pdf"') :Header). /* Die Datei zu senden ist das zweite Part des QUERY */ oEntity:AddPart(oFilePart). oRequest = RequestBuilder:post(" http://adresse_to_wsdl" , oEntity) :ContentType('multipart/related; type="application/xop+xml"; start=" "; start-info="text/xml"; boundary="' + vGUID + '"') :AddHeader('SOAPAction', ' adresse_to_WS/UploadFile') :AddHeader('Accept-Encoding', 'gzip,deflate') :AddHeader('MIME-Version', '1.0') :AddHeader('Connection', 'Keep-Alive') :Request. oResponse = ClientBuilder:Build() :Client:Execute(oRequest). /* Die Antwort ist auch in Multipart */ /* SOAP-RESPONSE Beispiel : 0 7bdab683-2c79-48e2-b051-b1b8dd628934 */ oResponseMultipartEntity = cast(oResponse:Entity,OpenEdge.Net.MultipartEntity). /* Grab the last part of the multi-part message and put it in a memptr */ oMessagePart = oResponseMultipartEntity:GetPart(oResponseMultipartEntity:Size). oByteBucket = cast(oMessagePart:Body,OpenEdge.Core.ByteBucket). oResponseMemptrEntity = oByteBucket:GetBytes(). copy-lob from oResponseMemptrEntity:Value to cResponse. create x-document hXDoc. cSoapHeader = cResponse. lcUTF-8 = codepage-convert(cSoapHeader, 'UTF-8'). hXDoc:load('LONGCHAR', lcUTF-8, false). hXDoc:encoding = 'UTF-8'. Set-Size(mData) = 0. HxDoc:save('LONGCHAR',cSoapHeader). dataset Envelope:read-xml( "longchar", cSoapHeader, ? , ?, ? ). /* Es gibt nur ein FileId zu lesen */ for each ttUploadResponse: if ttUploadResponse.ErrorCode <> "0" then do: message "Error : " skip ttUploadResponse.ErrorDescription view-as alert-box. return ?. end. FileId = ttUploadResponse.FileId. end.

Continue reading...
 
Status
Not open for further replies.
Top