JSON Web Services
2017 R1 Update Rollup 1

JSON Web ServicesPermanent link for this heading

Building JSON Web Services Using Fabasoft app.ducxPermanent link for this heading

To create web services that use JSON, the specific use cases have to be encapsulated within a Web Service Definition object (FSCOWS@1.1001:WebServiceDefinition).

In the following example, a web service contactaddress is used to fetch address data from a contact person who is identified via first name and surname.

Example

app.ducx Object Model Language

instance WebServiceDefinition JSONWebSvc {
  webserviceactions<webserviceoperation, webserviceaction> = {
    {
      "contactaddress",
      GetContactAddress
    }
  }
}

app.ducx Use Case Language

usecase GetContactAddress(string firstname, string surname, out Address address) {
  variant Object {
    impl = expression {
      if (firstname && surname) {
        string query = "LIMIT 1 SELECT objname FROM FSCFOLIO@1.1001:ContactPerson
          
where .userfirstname = '" + firstname +
          "' and .usersurname = '" + surname + "'";
        ContactPerson contact = coort.SearchObjects3(cootx, query);
        address = contact.address[0];
      }
    }
  }
}

Accessing JSON Web ServicesPermanent link for this heading

JSON web services can be accessed via a HTTP GET or HTTP POST method call via the “wsjson” Friendly URL.

HTTP GET RequestPermanent link for this heading

http://localhost/fsc/wsjson/JSONSAMPLE_1_1065_JSONWebSvc/contactaddress?firstname=Leo&surname=Mayr

The „wsjson“ Friendly URL takes two parameters:

  • The reference of the Web Service Definition object containing the web service action.
  • The operation name of the web service action.

In case of HTTP GET the parameters are transmitted as URL parameters.

HTTP POST RequestPermanent link for this heading

http://localhost/fsc/wsjson/JSONSAMPLE_1_1065_JSONWebSvc/contactaddress

In case of HTTP POST, the parameters are transmitted in the http request body as JSON string.

{
  "
firstname": "Cadence",
  "
surname": "Jones"
}

HTTP ResponsePermanent link for this heading

In both cases the result is sent in the HTTP response body.

Note: The key “address” within the JSON string corresponds to the outgoing parameter address of the GetContactAddress use case.

{
  "address": {

    "_": "Address",

    "
addrstreet": "Pfarrgasse 5",
    "
addrzipcode": "5409",
    "
addrcity": "Hallein",
    "
addrcountry": "Österreich",
    "
addrtopic": {
        "_": "
TermComponentObject",
        "
objaddress": "COO.1.1001.1.182477",
        "
objname": "Business"
    },

    "
addrsource": {
        "_": "
ContactPerson",
        "
objaddress": "COO.1.1065.3.402",
        "
objname": "Jones Cadence"
    }

  }

}