加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

macos – 如何使AppleScript SOAP与现有的SOAP Web服务一起工作(

发布时间:2020-12-14 23:24:35 所属栏目:资源 来源:网络整理
导读:我目前正在使用AppleScript编辑器. 我在那里运行以下代码: tell application "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL" call soap {method name:"CelsiusToFahrenheit",method namespace uri:"http://www.w3schools.com/webservices/"
我目前正在使用AppleScript编辑器.
我在那里运行以下代码:
tell application "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL"
    call soap {method name:"CelsiusToFahrenheit",method namespace uri:"http://www.w3schools.com/webservices/",parameters:{Celsius:50 as string},SOAPAction:"http://www.w3schools.com/webservices/CelsiusToFahrenheit"}
end tell

如果我执行上面的代码,我会得到一个“错误”字符串(这不是我的预期).
生成的请求如下:

<?xml version="1.0" encoding="utf-8"?>
  <SOAP-ENV:Envelope
    xmlns:xsd="http://www.w3.org/1999/XMLSchema"
    xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
      <SOAP-ENV:Body>
        <m:CelsiusToFahrenheit xmlns:m="http://www.w3schools.com/webservices/">
          <Celsius xsi:type="xsd:int">50</Celsius>
        </m:CelsiusToFahrenheit>
      </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

如果我像这样编辑请求(我使用Fiddler来编辑请求):

<?xml version="1.0" encoding="utf-8"?>
      <SOAP-ENV:Envelope
        xmlns:xsd="http://www.w3.org/1999/XMLSchema"
        xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
        SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
          <SOAP-ENV:Body>
            <CelsiusToFahrenheit xmlns="http://www.w3schools.com/webservices/">
              <Celsius xsi:type="xsd:int">50</Celsius>
            </CelsiusToFahrenheit>
          </SOAP-ENV:Body>
        </SOAP-ENV:Envelope>

>将“m:CelsiusToFarenheit”更改为“CelsiusToFarenheit”
>将“xmlns:m”更改为“xmlns”

我收到“122”,这是正确的答案.

我的问题是:

>为什么会这样? “call soap”函数使用的SOAP格式是旧格式吗?
>有没有办法解决这个问题(例如,在请求中删除“:m”或“m:”,或者通过在“call soap”方法中设置参数,通过代码使用不同的SOAP格式[我不知道这是不是可能])?

解决方法

瘦:

>调用soap功能中的一个错误忽略了命名空间标记正确调用的参数:方法名称元素以m:为前缀,但参数元素不是.
>解决方法是使用m:;显式地为参数名称添加前缀;在上面的例子中,使用| m:Celsius |而不是摄氏 – 请注意封闭|需要这些标志,因此您可以使用这样的名称,否则会破坏解析.

警告:如果Apple修复了这个bug,这个解决方法有可能会破坏.

将变通方法应用于上面的示例为我们提供:

tell application "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL"
  call soap {method name:"CelsiusToFahrenheit",?
            method namespace uri:"http://www.w3schools.com/webservices/",?
            parameters:{|m:Celsius|:50 as string},?
            SOAPAction:"http://www.w3schools.com/webservices/CelsiusToFahrenheit"}
end tell

背景:

  1. (…) Is the SOAP format used by the “call soap” function an old format?

缺点:AppleScript使用SOAP 1.1模式,虽然引擎盖下的API也支持SOAP 1.2,但您无法从AppleScript中选择它((您只能这样做from C using Carbon))

如上所述,SOAP XML构造有一个错误,这就是调用不起作用的原因. (http://www.w3schools.com/webservices/tempconvert.asmx的Web服务确实支持1.1,与1.2一起).

以下是有关call soap的重要性和维护状态以及调用xml-rpc功能的一些线索:

>这些功能在documentation separate from the AppleScript Language Guide中描述,即使它们似乎是语言本身的一部分(在任何外部词典中都找不到它们)
>该文档是在2001年编写的(从OSX 10.1开始;并且在2005年只看到了一个小小的修订版;警告可能会过时的Web服务URL :)).

‘2. Is there a way to fix this (e.g. remove “:m” or “m:” in the request or use different SOAP format through code by setting a parameter in the “call soap” method?

(参见上面的解决方法.)

基于文档状态线索,我不会屏住呼吸Apple的更新或修复 – 这很遗憾,因为这些功能看起来非常方便.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读