macos – 如何使AppleScript SOAP与现有的SOAP Web服务一起工作(
我目前正在使用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” 我收到“122”,这是正确的答案. 我的问题是: >为什么会这样? “call soap”函数使用的SOAP格式是旧格式吗? 解决方法
瘦:
>调用soap功能中的一个错误忽略了命名空间标记正确调用的参数:方法名称元素以m:为前缀,但参数元素不是. 警告:如果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 背景:
缺点: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中描述,即使它们似乎是语言本身的一部分(在任何外部词典中都找不到它们)
(参见上面的解决方法.) 基于文档状态线索,我不会屏住呼吸Apple的更新或修复 – 这很遗憾,因为这些功能看起来非常方便. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |