【问题标题】:consuming an external web service using marklogic使用 marklogic 使用外部 Web 服务
【发布时间】:2016-06-14 04:49:00
【问题描述】:

遇到困难。查找有关如何使用 marklogic 访问外部 Web 服务的示例? (也许我的搜索词有误?我也试过xdmp:http-getxdmp:http-post、发布http 请求、mash-up、编排)。

我首先需要了解,在我继续合并来自使用 ML 在一个页面中提供 3 个不同的 Web 服务(这个混搭的正确术语是什么?)。

将非常感谢使用 ML 的示例。我见过 celsiusfahrenheit 的转换示例,还有股票报价请求和响应,但在 ML 中没有。我不知道如何或从哪里开始。你能指出我正确的方向吗?渴望学习将 ML 用于 Web 服务。

非常感谢。

【问题讨论】:

    标签: web-services xquery marklogic


    【解决方案1】:

    我想说这里有例子: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))),
        "&amp;"
      )
    }
    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!

    【讨论】:

    • 非常感谢。您的回复示例让我更清楚,在 ml xdmp:http-post 上阅读更多内容。
    • 我不清楚这一点:如果我在一页中使用 3 个 Web 服务,我需要做的就是写 3 let $envelop := .... return xdmp:http-post( ...) FLOWR 块,如您的示例中所示?再次感谢您对 ML/xquery 新手的耐心回复。
    • 我建议将每个调用包装在一个函数中以使其更容易,然后使用let $res1 := my:func1(..) let $res2 := my:funky(..) return &lt;results&gt;{$res1, $res2}&lt;/results&gt; 之类的东西将结果粘合在一起..
    • 如果不够清楚,请单独发布一个问题,cmets 太短,无法很好地解释..
    猜你喜欢
    • 2012-06-06
    • 1970-01-01
    • 2013-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-18
    • 1970-01-01
    • 2015-09-24
    相关资源
    最近更新 更多