Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function GetItem(out JsonResponse, SoapError: WideString): UInt8; stdcall;
- var
- RIO: THTTPRIO;
- WS: WebIntegration_Port;
- WsItems: Items;
- RecordsReceived: Integer;
- RecordCount: Integer;
- I: Integer;
- JItems: TItems;
- begin
- try
- // *** THTTPRIO will free itself when created with no owner
- // http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Calling_Invokable_Interfaces
- RIO := THTTPRIO.Create(nil);
- except
- on E: Exception do
- begin
- SoapError := E.Message;
- Exit(SOAP_ERROR);
- end;
- end;
- RIO.HTTPWebNode.UserName := FUserName;
- RIO.HTTPWebNode.Password := FPassword;
- RIO.URL := FURL;
- if FUseProxy then
- begin
- RIO.HTTPWebNode.Proxy := FProxy;
- end;
- try
- WS := (RIO as WebIntegration_Port);
- // We get Total record count with first call to WebService
- WS.Item(WsItems, EmptyStr, False, EmptyStr, 1, 1, RecordCount);
- // Now, we know how many records in there. We can get them all
- WS.Item(WsItems, EmptyStr, False, EmptyStr, 1, RecordCount, RecordsReceived);
- // Do not depend on RecordsReceived variable returning from WebService. Count it yourself
- SetLength(JItems, Length(WsItems));
- for I := Low(WsItems) to High(WsItems) do
- begin
- JItems[i].FNo := WsItems[i].No;
- JItems[i].FDescription := WsItems[i].Description;
- JItems[i].FUoM := WsItems[i].UoM;
- JItems[i].FPrice := BcdToDouble(WsItems[i].Price.AsBcd);
- JItems[i].FStock := BcdToDouble(WsItems[i].Stock.AsBcd);
- end;
- WS := nil;
- // mORMot json routines used for building json string reply.
- JsonResponse := WideString(RecordSaveJSON(JItems, TypeInfo(TItems)));
- except
- on E: Exception do
- begin
- SoapError := E.Message;
- Exit(SOAP_ERROR);
- end;
- end;
- Result := RESPONSE_OK;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement