度过了一段艰难时期。查找示例,如何使用marklogic访问外部Web服务? (也许我的搜索字词有误?我还尝试了xdmp:http-get
,xdmp:http-post
,发布了http请求,mash-up
,编排了一下。
我首先需要理解,在MarkLogic
中编写脚本以访问一个外部(非ML)Web服务并在继续组合之前显示响应将是多么困难(希望很容易) 3个不同的Web服务的结果(这个混搭的正确术语?)在一个页面中使用ML。
使用ML的例子将是最受欢迎的。我已经看到摄氏到 fahrenheit 转换示例,还有股票报价请求和响应但不在ML中。我不知道如何或从哪里开始。你能指点我正确的方向吗?渴望学习使用ML进行Web服务。
非常感谢。答案 0 :(得分:3)
我会说这里有例子:http://docs.marklogic.com/xdmp:http-post
但为了完整起见,我还要补充一下:
基于: http://www.w3schools.com/xml/tempconvert.asmx?op=FahrenheitToCelsius
SOAP 1.1:
let $envelop :=
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<FahrenheitToCelsius xmlns="http://www.w3schools.com/xml/">
<Fahrenheit>100</Fahrenheit>
</FahrenheitToCelsius>
</soap:Body>
</soap:Envelope>
return
xdmp:http-post(
"http://www.w3schools.com/xml/tempconvert.asmx",
<options xmlns="xdmp:http">
<headers>
<Content-Type>text/xml; charset=utf-8</Content-Type>
<SOAPAction>"http://www.w3schools.com/xml/FahrenheitToCelsius"</SOAPAction>
</headers>
</options>,
$envelop
)
SOAP 1.2:
let $envelop :=
<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>
<FahrenheitToCelsius xmlns="http://www.w3schools.com/xml/">
<Fahrenheit>100</Fahrenheit>
</FahrenheitToCelsius>
</soap12:Body>
</soap12:Envelope>
return
xdmp:http-post(
"http://www.w3schools.com/xml/tempconvert.asmx",
<options xmlns="xdmp:http">
<format xmlns="xdmp:document-get">xml</format>
<headers>
<Content-Type>application/soap+xml; charset=utf-8</Content-Type>
</headers>
</options>,
$envelop
)
HTTP POST:
let $body := text {
string-join(
("Fahrenheit=" || encode-for-uri(string(100))),
"&"
)
}
return
xdmp:http-post(
"http://www.w3schools.com/xml/tempconvert.asmx/FahrenheitToCelsius",
<options xmlns="xdmp:http">
<headers>
<Content-Type>application/x-www-form-urlencoded</Content-Type>
</headers>
</options>,
$body
)
HTH!