応答のカスタマイズ

  • リリースバージョン: Washingtondc
  • 更新日 2024年02月01日
  • 読む2読むのに数分
  • この例に従って、SOAP 応答の XML ペイロードをカスタマイズおよび制御します。

    始める前に

    必要なロール:web_service_admin または admin

    手順

    1. XMLDocument スクリプトインクルードオブジェクトを使用して、カスタマイズされた XML ドキュメントを作成します。
      注:
      スコープ対象のアプリケーションでスクリプト利用 Web サービスを作成する場合は、 XMLDocument2 API を使用する必要があります。
    2. ドキュメント要素をスクリプト利用 Web サービスの変数 response.soapResponseElement に設定します。
      たとえば、次のスクリプト利用 Web サービススクリプトの場合
      var xmldoc = new XMLDocument2();
          xmldoc.parseXML("<myResponse></myResponse>");
          xmldoc.createElementWithTextValue("element_one", "test");  
          xmldoc.createElementWithTextValue("element_two", "new2 value");  
      
          var el = xmldoc.createElement("element_three");
          xmldoc.setCurrentElement(el);  
          xmldoc.createElementWithTextValue("newChild", "test child element");
      
          response.soapResponseElement = xmldoc.getDocumentElement();
      次の要求を受け入れるために使用されます。
      <soapenv:Envelope 
         xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
         xmlns:tes="http://www.service-now.com/TestCustomResponse">
         <soapenv:Header/>
         <soapenv:Body>
            <tes:execute/>
         </soapenv:Body>
      </soapenv:Envelope>
      これは、次の SOAP 応答で応答します。
      <soapenv:Envelope 
          xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
          xmlns:tes="http://www.service-now.com/TestCustomResponse">
         <soapenv:Header/>
         <soapenv:Body>
            <myResponse>
               <element_one>test</element_one>
               <element_two>new2 value</element_two>
               <element_three>
                  <newChild>test child element</newChild>
               </element_three>
            </myResponse>
         </soapenv:Body>
      </soapenv:Envelope>

      WSDL サポートは外部で作成する必要があります。SOAP エンドポイントは、問題のスクリプト利用 Web サービスを再び参照する必要があります。