我尝试与otrs-ticketsystem进行交互以便制作
几张图片并计算一些统计数据。我想在haskell
- 我做
使用包soap
。
忽略import语句代码非常简单,我创建了一个
带有配置文件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>
我在互联网上搜索了一些解决方案,我只找到了这个
最后一个我成功地设法得到了一个结果 - 但仅限于 iPhoneObject和TicketGet - 遗憾的是TicketSearch似乎不是 支撑。
我还找到了How to create an otrs ticket using a soap request .Net - 它使用了网络 服务 - 但不幸的是我不知道如何创建这样的服务。
答案 0 :(得分:0)
您将在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>