How to Work with Web Service in Fore?

Description

PP.SOM service is mostly used to develop web application based systems. Somehow it may be required to address the web service from desktop application based assemblies, forms or units. The Fore language interacts with various network resources via POST/GET requests using the NetHttpService class of the Net assembly. Working with the web service is executed via the SOAP protocol.

To work with the web service:

  1. Create an instance of the NetHttpService class, specify in the Url property the web service URL and execute the Connect method. The rules for creating a web service URL are given in the Connecting to Web Service subsection.

  2. Cast the obtained object described by the INetCommand interface to the INetHttpCommand interface and determine settings to work with the web service: Command = NetHttpCommandType.Post.

  3. Create SOAP request to execute the required operation. Description of operations and examples of their use are given in the Web Service Operations subsection.

  4. Send the created SOAP request to the Start method to send the request to the web service.

  5. The Result property will contain the web server response.

Example

Below is the example of connecting to the PP.SOM web service and sending a repository connection request. After the connection is established successfully, the development environment console will displays the web service response and the moniker, via which al the further work with the repository is executed. After the work is completed, the repository is disconnected.

Sub TestSOAPRequest;
Var
    Service: INetHttpService;
    Cmd: INetCommand;
    HttpCmd: INetHttpCommand;
    Request: Variant;
    Response, Id: string;
Begin
    Service := New NetHttpService.Create;
    Service.Url := "http://localhost:9090/axis2/services/PP.SOM.Som";
    // Connect to web service
    Cmd := Service.Connect;
    HttpCmd := Cmd As INetHttpCommand;
    HttpCmd.Command := NetHttpCommandType.Post;
    HttpCmd.AcceptLanguage := "ru";
    // Connect to repository
    Request := "<OpenMetabase>" +
        "<tDef><id>TEST_REPOSITORY</id></tDef>" +
        "<tCreds><user><id>user</id></user><pass>password</pass></tCreds>" +
        "</OpenMetabase>" ;
    Cmd.Start(Request);
    Response := Cmd.Result As String;
    Id := Response.SubString(Response.IndexOf("<id>") + 4, Response.IndexOf("</id>") - Response.IndexOf("<id>") - 4);
    Debug.WriteLine("Response: " + Response);
    Debug.WriteLine("Moniker: " + Id);
    //...
    // Further work with repository
    //...
    // Disconnect from repository
    Request := "<CloseMetabase><tMb><id>" + id + "</id></tMb></CloseMetabase>";
    Cmd.Start(Request);
End Sub TestSOAPRequest;

See also:

Questions and Answers