使用 Savon gem 格式化 SOAP API 的问题

Issues Formatting a SOAP API with Savon gem

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

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

基本上我想做的是:

第 1 步:调用 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 的新手。如有任何帮助,我们将不胜感激。如果需要进一步的帮助,请告诉我。

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

之后就比较容易跟上了。好像所有的操作都是一样的header,所以我会去创建一个看起来像

的客户端
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' })