gpt4 book ai didi

macos - 如何让 AppleScript SOAP 与现有的 SOAP 网络服务一起工作(例如 W3Schools 的CelsiusToFarenheit 示例)?

转载 作者:行者123 更新时间:2023-12-04 20:43:20 25 4
gpt4 key购买 nike

我目前正在使用 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”,这是正确的回应。

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

    瘦子:

  • A call soap 中的错误功能 忽略命名空间标记适本地提供给调用的参数:方法名称元素以 m: 为前缀。 ,但参数元素不是。
  • 解决方法是到 m: 显式地为参数名称添加前缀 ;在上面的例子中,使用 |m:Celsius|而不是 Celsius - 请注意封闭的 |需要标志,因此您可以使用这样的名称,否则会破坏解析。

  • 警告 :如果 Apple 修复了该错误,则此解决方法可能会中断。

    将解决方法应用于上述示例为我们提供了:

    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 的重要性和维护状态的一些线索。和 call 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 获得更新或修复——这很遗憾,因为这些功能看起来真的很方便。

    关于macos - 如何让 AppleScript SOAP 与现有的 SOAP 网络服务一起工作(例如 W3Schools 的CelsiusToFarenheit 示例)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22296471/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com