21
Oct
2015
BlueSnow

【Drupal】使用SOAP服务:利用Web服务客户端模块和规则模块

原文链接:http://drupal.org/node/1114308 (link is external)

介绍

本节通过例子描述在规则 (link is external)内使能Web客户端模块 (link is external),来使用SOAP服务。

What

例子:温度转换

HOW

  • 1. 添加一个web服务描述
  • 2. 创建用户输入的节点表单(创建节点)
  • 3. 使用规则 (link is external)创建工作流程(快照 (link is external)
    • 事件:保存后的新内容(after saving new content)
    • 条件:给定的内容类型(content is of given type)
    • 行动:创建一个数据结构(create a data structure)
    • 动作:调用Web服务(call web service )(使用Web服务客户端 (link is external)
    • 行动:显示结果(display result)

Requirements

说明

(所有的快照集 (link is external).)

保存没有错误的Web服务描述 (screenshot (link is external))

  • 1. 管理 -> 配置 -> Web服务 -> Web服务描述 -> 增加Web服务描述 (快照 (link is external))
  • 2. 添加内容类型“Celsius to Fahrenheit(摄氏到华氏)”,并增加浮点类型的温度输入字段(快照 (link is external)
  • 3. 管理 - >配置 - >流程 - >规则 - >添加新的规则:“Celsius to Fahrenheit(摄氏到华氏)”,事件选项为“After saving new content(新内容保存后的)”(快照 (link is external)
  • 4. 管理 - >配置 - >流程 - >规则 - >编辑应对规则(Editing reaction rule)“Celsius to Fahrenheit(摄氏到华氏)”
    • 加入条件:内容类型是“Celsius to Fahrenheit(摄氏到华氏)”(快照 (link is external)
    • 添加一个新的动作:创建一个数据结构(Create a data structure )
      • 选择动作,数据>创建一个数据结构(Data > Create a data structure)(快照 (link is external)
      • 类型:值:“Temperature Converter(温度转换器):CelsiusToFahrenheit”(快照 (link is external)
      • 继续
      • 摄氏(CELSIUS): 值(Value): [node:field-ctf-temp] (温度输入字段的名称) (快照 (link is external)
      • 已提供的变量(Provided variables):已创建的数据(CREATED DATA)(快照 (link is external)
        • 变量标签:Celsius input
        • 变量名:celsius_input
      • 保存
    • 添加一个新的动作(Add a new action): "Temperature Converter(温度转换器): CelsiusToFahrenheit"
      • 添加一个新的动作(Select the action to add): Web服务(Web services) > "Temperature Converter(温度转换器): CelsiusToFahrenheit" (快照 (link is external))
      • 参数设置和名称 (快照)
        • 参数(PARAMETERS): 数据选择器(Data selector): celsius-input (在数据结构中指定的名称)
        • 已提供的变量(Provided variables): CELSIUSTOFAHRENHEITRESPONSE
          • 变量标签(Variable label): CelsiusToFahrenheitResponse
          • 变量名(Variable name): fahrenheit_output
        • Save
    • 添加一个新的动作: 在网页上显示消息(选项1:数据选择器)
      • 选择添加动作:系统>在网页上显示消息(System>Show a message on the site)(快照 (link is external)
      • 在消息(MESSAGE)中,选中按钮“切换到数据选择器(switch to data selector)“
      • 在数据选择器(Data selector)中输入: "fahrenheit-output:CelsiusToFahrenheitResult"(Web服务输出中的名称)
      • 保存
    • 添加一个新的动作: 在网页上显示消息(选项2:数据选择器和PHP evalution(需要PHP过滤器模块))
      • 选择添加动作:系统>在网页上显示消息(System>Show a message on the site)(快照 (link is external)
      • 在消息(MESSAGE)中使用数据选择器和PHP evalution(需要PHP过滤器)(快照 (link is external)
        • 消息:数据选择器(MESSAGE: Data selector): "fahrenheit-output:CelsiusToFahrenheitResult"
        • 消息:PHP EVALUATION(MESSAGE: PHP EVALUATION): return $value . ' Fahrenheit'; (不要包含
          <?php
           
          ...
          ?>

          标签)

    • 添加一个新的动作: 在网页上显示消息(选项3:直接输入和PHP evalution(需要PHP过滤器模块))
      • 选择添加动作:系统>在网页上显示消息(System>Show a message on the site)(快照 (link is external)
      • 在消息(MESSAGE)中使用直接输入和PHP evalution(需要PHP过滤器)(快照 (link is external)
        • 消息:值(MESSAGE: Value):
          									<?php
          // var_dump($celsius_input); // do this to learn about the variable at hand
          // var_dump($fahrenheit_output);
          echo $celsius_input['Celsius'] . ' Celsius is ' . $fahrenheit_output->CelsiusToFahrenheitResult . ' Fahrenheit';
          ?>
        • 消息(MESSAGE): PHP EVALUATION: 查看变量名
  • 5. 完成规则 "Celsius to Fahrenheit(摄氏到华氏)" (快照 (link is external))
    • 事件(Events)
      • 新内容保存后(After saving new content)
    • 条件(Conditions)
      • 内容类型是(Content is of type) "Celsius to Fahrenheit(摄氏到华氏)"
    • 动作(Actions)
      • 创建一个数据结构(Create a data structure) "Temperature Converter(温度转换器): CelsiusToFahrenheit"
      • 调用Web服务(Call web service) "Temperature Converter(温度转换器): CelsiusToFahrenheit"
      • 在网页上显示消息(Show a message on the site option) "data selector(数据选择器)"
      • 在网页上显示消息(Show a message on the site option) "data selector with PHP(数据选择器和PHP)"
      • 在网页上显示消息(Show a message on the site option) "direct input with PHP(直接输入和PHP)"
  • 6. 创建类型为 "Celsius to Fahrenheit"的内容,完成 :-) (快照 (link is external))

执行结果:每次创建新内容保存后,呈现转换结果的提示条

Source: