我尝试与otrs-ticketsystem进行互动,以使
一些图片并计算一些统计数据。我想用haskell做到这一点-我
使用软件包 soap
忽略导入语句的代码相当简单,我创建了一个
带有配置文件soap.cfg的SOAP-transport(请参见下文)。然后构造
SOAP-Body并使用"Dispatch"调用Web服务。

{-# LANGUAGE OverloadedStrings #-}

import Network (withSocketsDo)
import Network.SOAP
import Network.SOAP.Transport.HTTP

import Text.XML.Writer
import Text.XML.Stream.Parse as Parse
import           Data.Text (Text)
import qualified Data.Text as T
import qualified Data.ByteString.Lazy.Char8 as BS
import Data.Configurator (load, Worth(Required))

main :: IO ()
main = withSocketsDo $ do
    transport <- confTransport "soap" =<< load [Required "./src/SOAP/soap.cfg"]
    let body = do element "TicketObject" ("TicketSearch" :: Text)
                  element "OwnerID" ("owner" :: Text)

    xmlresult <- invokeWS transport "#TicketObject" () body (RawParser id)
    BS.putStrLn xmlresult
soap.cfg
soap {
    url = "http://domain/otrs/rpc.pl"
    user = "testuser"
    password = "testpass"
    trace = true
    timeout = 15
    }
如果我构建并调用此程序,则会得到以下xmlresult:
要求:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <TicketObject>TicketSearch</TicketObject>
        <OwnerID>heu</OwnerID>
    </soapenv:Body>
</soapenv:Envelope>
回复:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
    soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soap:Body>
        <soap:Fault>
            <faultcode>soap:Client</faultcode>
            <faultstring>
                SOAPAction shall match 'uri#method' if present (got 'Dispatch', expected '#TicketObject'
            </faultstring>
        </soap:Fault>
    </soap:Body>
</soap:Envelope>
如果我再更改以下行
xmlresult <- invokeWS transport "Dispatch" () body (RawParser id)
xmlresult <- invokeWS transport "#TicketObject" () body (RawParser id)
故障字符串变为
<faultstring>
    Denied access to method (TicketObject) in class (main) at /opt/otrs/Kernel/cpan-lib/SOAP/Lite.pm line 2810.
</faultstring>
我在互联网上搜索了一些解决方案,但我只找到了这个
  • http://otrs.perl-services.de/…
    关于票务搜索,当然还有OTRS 3.3 API
  • http://blog.otrs.org->票务搜索(perl)
  • OTRS Client in Java
  • OTRS iPhoneObject providing JSON

  • 与最后一个我成功地获得了结果-但仅适用于
    iPhoneObject和TicketGet-不幸的是,TicketSearch似乎不是
    支持的。
    有人可以告诉我该请求的有效XML是什么样的吗?
    我还发现How to create an otrs ticket using a soap request .Net-使用网络
    服务-但不幸的是,我不知道如何创建这样的服务。

    最佳答案

    您可以在Using javax.xml.soap to access OTRS SOAP service without WSDL中找到一个XML代码段。

    这是perl script产生的请求跟踪

    Accept: text/xml
    Accept: multipart/*
    Accept: application/soap
    Content-Length: 707
    Content-Type: text/xml; charset=utf-8
    SOAPAction: "/Core#Dispatch"
    
    <?xml version="1.0" encoding="UTF-8"?><soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><Dispatch xmlns="/Core"><Username xsi:type="xsd:string">foo</Username><Password xsi:type="xsd:string">bar</Password><Object xsi:type="xsd:string">TicketObject</Object><Method xsi:type="xsd:string">TicketSearch</Method><Param1_Name xsi:type="xsd:string">TicketID</Param1_Name><Param1_Value xsi:type="xsd:int">561141</Param1_Value></Dispatch></soap:Body></soap:Envelope>
    SOAP::Transport::HTTP::Client::send_receive: HTTP::Response=HASH(0x557656ccebb0)
    SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK
    Connection: close
    Date: Mon, 18 Mar 2019 16:35:20 GMT
    Vary: Accept-Encoding
    Content-Length: 416
    Content-Type: text/xml; charset=utf-8
    Client-Date: Mon, 18 Mar 2019 16:35:21 GMT
    Client-Peer: 85.239.118.197:443
    Client-Response-Num: 1
    Client-SSL-Cert-Issuer: /C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Domain Validation Secure Server CA
    Client-SSL-Cert-Subject: /OU=Domain Control Validated/OU=EssentialSSL Wildcard/CN=*.pyur.com
    Client-SSL-Cipher: ECDHE-RSA-AES128-GCM-SHA256
    Client-SSL-Socket-Class: IO::Socket::SSL
    Set-Cookie: TS0179c75b=013dfe6b3e1266bc1210a8bb5e6a9352943012e3f1d5767b07f5ec8a310bb53c004c09e467d982f0117fe8a3f6aa1dee4e812153c4; Path=/; Domain=.ticketsystem.pyur.com
    SOAPServer: SOAP::Lite/Perl/1.11
    
    <?xml version="1.0" encoding="UTF-8"?><soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><DispatchResponse xmlns="/Core" xsi:nil="true" /></soap:Body></soap:Envelope>
    

    10-06 08:54