【问题标题】:Issues Formatting a SOAP API with Savon gem使用 Savon gem 格式化 SOAP API 的问题
【发布时间】:2020-11-18 02:35:10
【问题描述】:

我很害怕这一天会到来……处理 SOAP API 的……

这对我来说是一个全新的领域,我已经用 SAVON gem 进行了一些挖掘,但我似乎无法构建我的调用..

基本上我想做的是以下几点:

第一步:调用API获取LatestCallerVersion(API版本)

第 2 步:获取 LatestCallerVersion 并向验证 API 发送第二个请求,以查看我的客户是否在有效的服务区域内。

这是我想出的(但它会崩溃并烧毁)

caller_client = Savon.client(
  wsdl: 'https://alarmadmin.alarm.com/webservices/CustomerManagement.asmx?WSDL '\
)
caller_response = caller_client.call(
  :authentication,
  message: {
      user: 'xxxxxx',
      password: 'xxxxxx',
      two_factor_device_id: 'xxxxxx'
  },
  :body,
  message: {
      :get_latest_caller_version
  }
)

这是 GetLatestCaller 调用的 SOAP 请求和响应文档

POST /webservices/CustomerManagement.asmx HTTP/1.1
Host: alarmadmin.alarm.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Header>
    <Authentication xmlns="http://www.alarm.com/WebServices">
      <User>string</User>
      <Password>string</Password>
      <TwoFactorDeviceId>string</TwoFactorDeviceId>
    </Authentication>
  </soap12:Header>
  <soap12:Body>
    <GetLatestCallerVersion xmlns="http://www.alarm.com/WebServices" />
  </soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <GetLatestCallerVersionResponse xmlns="http://www.alarm.com/WebServices">
      <GetLatestCallerVersionResult>int</GetLatestCallerVersionResult>
    </GetLatestCallerVersionResponse>
  </soap12:Body>
</soap12:Envelope>

这里是 CheckCaller_V2 请求和响应

POST /webservices/Validate.asmx HTTP/1.1
Host: alarmadmin.alarm.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Header>
    <Authentication xmlns="http://www.alarm.com/WebServices">
      <User>string</User>
      <Password>string</Password>
      <TwoFactorDeviceId>string</TwoFactorDeviceId>
    </Authentication>
  </soap12:Header>
  <soap12:Body>
    <CheckCoverage_v2 xmlns="http://www.alarm.com/WebServices">
      <input>
        <Address>
          <Street1>string</Street1>
          <Street2>string</Street2>
          <SubCity>string</SubCity>
          <City>string</City>
          <SubState>string</SubState>
          <State>string</State>
          <Zip>string</Zip>
          <CountryId>Canada</CountryId>
        </Address>
        <Network>Gsm</Network>
        <Generation>FourG</Generation>
        <CallerVersion>returned from GetLatestCaller call</CallerVersion>
      </input>
    </CheckCoverage_v2>
  </soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <CheckCoverage_v2Response xmlns="http://www.alarm.com/WebServices">
      <CheckCoverage_v2Result>NotChecked or FullCoverage or MostlyCovered or NoCoverage or Error or BadZip or PartialCoverage or NotSupported or NotOffered</CheckCoverage_v2Result>
    </CheckCoverage_v2Response>
  </soap12:Body>
</soap12:Envelope>

我是 SOAP 的新手,我们将不胜感激任何帮助。如果需要任何进一步的信息,请告诉我。

【问题讨论】:

    标签: ruby-on-rails soap savon


    【解决方案1】:

    请使用 SOAP UI 检查请求定义。在 SOAP UI 中加载 WSDL 文件时,我可以获得以下信息。

    之后,它变得相对容易跟随。似乎所有操作都有相同的标头,所以我将创建一个看起来像的客户端

    caller_client = Savon.client(
              wsdl: 'https://alarmadmin.alarm.com/webservices/CustomerManagement.asmx?WSDL',
              env_namespace: :soapenv,
              namespace_identifier: :web,
              soap_header: {
                'web:Authentication': {
                  'web:User': 'xxxx',
                  'web:Password': 'xxxxx',
                  'web:TwoFactorDeviceId': 'xxx'
                }
              })
    

    然后调用单个操作就变成了

    caller_client.call(:get_latest_caller_version)
    

    如果要列出所有可能的操作,可以使用

    caller_client.operations
    

    如果要将消息传递给单个操作,请使用以下格式

       caller_client.call(:get_modem_serial_from_iccid, message: { iccid: 'xxxx' })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多