I'm presently working on a project that requires utilizing a VL-generated web service. This service operates flawlessly during POSTMAN testing. However, when trying to connect with the service through VL-Web, I face a challenge: sending with parameters in String format instead of JSON, I tried working with #XPRIM_JsonObject but it's not supported by the web. Consequently, I have to manually parse the string upon transmission. Dealing with multiple inputs or outputs involves substring operations on the string, which isn't an ideal or efficient solution.
Part of my API :
Code: Select all
Srvroutine Name(CreateIntermediaire) Response(*HTTP £Context)
* Instance of the CreateIntermediaires Operation
Define_Com Class(£Com_Home.CreateIntermediaire) Name(£Operation)
* Instance of the IntermediaireObject Component used by Operation CreateIntermediaires
Define_Com Class(£Com_Home.IntermediaireObject) Name(£IntermediaireObject)
* Try to Bind the CreateIntermediaire Operation to the HTTP £Context.
If (£Operation.TryBind( £Context ))
Get Com(£Operation.Request.ContentJson) Com_Fields(£IntermediaireObject)
* If Identifier not included in the json and not an Identity Column then set value now
* £INTMED := *AUTONUMnn£INTMED
* Pre-check data set and automatically generate a 400 response if any errors. All messages are collected and send back using the "xUnexpectedError" Schema
Begincheck
Filecheck Field(£INTMED) Using_File(INTERMED) Using_Key(£INTMED) Found(*ERROR) Not_Found(*NEXT) Msgtxt("Intermediaire with ID " + £INTMED.asstring + " already exists")
Insert Fields(£IntermediaireObject) To_File(INTERMED) Io_Error(*NEXT) Val_Error(*NEXT) Check_Only(*YES)
If_Status Is_Not(*OKAY)
Message Msgtxt("Intermediaire with ID " + £INTMED.asstring + " includes invalid data")
Endif
Endcheck If_Error(*RETURN400)
Insert Fields(£IntermediaireObject) To_File(INTERMED) Io_Error(*NEXT) Val_Error(*NEXT)
If (£Operation.CheckIoStatus( £IO$STS ))
Set Com(£IntermediaireObject) Com_Fields(£IntermediaireObject)
£Operation.Response.SetContentJson( £IntermediaireObject )
Endif
Else
* Bad Response automatically handled by LANSA
Endif
EndroutinePart of Webpage :
Code: Select all
Mthroutine Name(DoRequest)
Define_Com Class(£prim_web.HttpRequest) Name(£request)
Define_Com Class(£prim_web.json) Name(£json)
* Define_Com Class(£ws_back_client.Insert) Name(£ContactObject)
* Define_Com Class(£WS_Contact_V1.write)
£request.Content := '{"INTMED" :"' + £Edit.value + '","NAME":"' + £Edit3.Value + '"}'
£request.Content := £request.Content.Text
£sys_web.Alert Caption(£request.Content.Text)
£request.Url := ('http://localhost/FOR/ws_intermed/Intermediaires?=')
£request.Method := POST
£json.CreateRootObject
£request.Execute
Evtroutine Handling(£request.Completed)
If (£request.Response.StatusCode = 200)
£sys_web.Alert Caption("ALL good, client well added !")
£sys_web.Alert Caption("content response : " + £request.Response.Content.Text)
Else
£sys_web.Alert Caption("l'ajout a echoué code : " + £request.Response.StatusCode.AsString)
£sys_web.Alert Caption("content response : " + £request.Response.Content.Text)
Endif
Endroutine
Evtroutine Handling(£request.Failed)
Endroutine
EndroutineThanks in advance.
Naek