2016-06-02 2 views
1

이 방법을 설명하는 튜토리얼 또는 예제 문서가 있습니까? HTTP 요청을 할 수있는 Drakma HTTP 클라이언트를 볼 수 있지만 실제로 SOAP WebService를 호출하는 방법을 실제로 이해하지 못합니다 (심지어 가능하다면). 모든 지침 정말 감사하겠습니다.Common Lisp에서 SOAP 웹 서비스를 사용하는 방법은 무엇입니까?

+0

[리스프 비누 클라이언트 (의 가능한 중복 http://stackoverflow.com/questions/1396652/lisp-soap- 클라이언트) – lifeisfoo

답변

1

일반적인 lisp cl-soap 용 비누 클라이언트가 있지만 구식 인 것 같습니다. HTTP는 HTTP를 통해 구현되므로 drakma를 사용하여 SOAP 서비스로 쉽게 호출 할 수 있습니다. 우리는 또한 사용합니다 :

clozure 일반적인 lisp 또는 당신처럼 구현 SBCL quicklisp cl-ppcre; 이식 가능한 정규식 librarie plump; 그것은이 내부에 두 개의 매개 변수를 전달 그들을주의 깊게

읽어

여기

http://www.webservicex.net/New/Home/ServiceDetail/56 당신이 비누 서비스에 대한 원시 요청을 찾을 수 있습니다 XML 파서는

은의 여기 http://www.webservicex.net/New/ 쉽게 하나가 될 수에서 비누 서비스를 부르 자 xml body를 입력 한 다음 하나의 xml을 다시 보냅니다.

soap 서비스는 쉽게 받아 들일 수 있으며 XML을 보내고 XML을 수신하는 HTTP 게시 메소드는 drakma를 사용하여 호출을 구성합니다.

는 SOAP 서비스의 중요한 파일은 WSDL 인 서비스의 설명입니다

http://www.webservicex.net/globalweather.asmx?WSDL

가의 리스프와 놀자 :

;; preparing the xml soap 

(defun create-body-for-request-get-weather-soap (city-name country-name) 
    (format nil "~{~A~%~}" (list 
          "<?xml version=\"1.0\" encoding=\"utf-8\"?>" 
          "<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>" 
          "<GetWeather xmlns=\"http://www.webserviceX.NET\">" 
           (format nil "<CityName>~A</CityName>" city-name) 
           (format nil "<CountryName>~A</CountryName>" country-name) 
          "</GetWeather>" 
          "</soap:Body>" 
          "</soap:Envelope>"))) 

(defun send-soap-request (&key url soap-action soap-body) 
    (let* ((response 
      (drakma:http-request url 
           :method :post 
           :content-length t 
           :content-type "text/xml; charset=utf-8" 
           :additional-headers `(("SOAPAction" . ,soap-action)) 
           :content soap-body))) 
    response)) 

(defparameter answer (send-soap-request 
         :url "http://www.webservicex.net/globalweather.asmx" 
         :soap-action "http://www.webserviceX.NET/GetWeather" 
         :soap-body (create-body-for-request-get-weather-soap "Valencia" "Spain"))) 



;;preparing the xml soap 1.2 



(defun create-body-for-request-get-weather-soap12 (city-name country-name) 
    (format nil "~{~A~%~}" 
      (list "<?xml version=\"1.0\" encoding=\"utf-8\"?>" 
       "<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>" 
        "<GetWeather xmlns=\"http://www.webserviceX.NET\">" 
         (format nil "<CityName>~A</CityName>" city-name) 
         (format nil "<CountryName>~A</CountryName>" country-name) 
        "</GetWeather>" 
        "</soap12:Body>" 
       "</soap12:Envelope>"))) 

(defun send-soap12-request (&key url soap-action soap-body) 
    (let* ((response 
      (drakma:http-request url 
           :method :post 
           :content-length t 
           :content-type "application/soap+xml; charset=utf-8" 
           :additional-headers `(("SOAPAction" . ,soap-action)) 
           :content soap-body))) 
    response)) 



;; the call 

(defparameter answer (send-soap12-request 
         :url "http://www.webservicex.net/globalweather.asmx" 
         :soap-action "http://www.webserviceX.NET/GetWeather" 
         :soap-body (create-body-for-request-get-weather-soap12 "Valencia" "Spain"))) 

(class-of answer) ;; I do not know if I have an error with the codification, but in this case seems 
;;and error with utf-8 and utf-16, so it returns and array of unsignet bytes it seems ascii so I convert it with common lisp 

(format nil "~{~A~}" (map 'list #'(lambda (value) (code-char value)) answer)) 

및 답변 :

; 응답 옥텟에 대한 값

CL-USER> 
; No value; compiling (DEFUN CREATE-BODY-FOR-REQUEST-GET-WEATHER-SOAP ...) 
; compiling (DEFUN SEND-SOAP-REQUEST ...) 
CL-USER> answer 

"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body><GetWeatherResponse xmlns=\"http://www.webserviceX.NET\"><GetWeatherResult>&lt;?xml version=\"1.0\" encoding=\"utf-16\"?&gt; 
&lt;CurrentWeather&gt; 
    &lt;Location&gt;Valencia/Aeropuerto, Spain (LEVC) 39-30N 000-28W 62M&lt;/Location&gt; 
    &lt;Time&gt;Jun 07, 2016 - 06:30 AM EDT/2016.06.07 1030 UTC&lt;/Time&gt; 
    &lt;Wind&gt; from the E (080 degrees) at 9 MPH (8 KT) (direction variable):0&lt;/Wind&gt; 
    &lt;Visibility&gt; greater than 7 mile(s):0&lt;/Visibility&gt; 
    &lt;SkyConditions&gt; mostly clear&lt;/SkyConditions&gt; 
    &lt;Temperature&gt; 78 F (26 C)&lt;/Temperature&gt; 
    &lt;DewPoint&gt; 57 F (14 C)&lt;/DewPoint&gt; 
    &lt;RelativeHumidity&gt; 47%&lt;/RelativeHumidity&gt; 
    &lt;Pressure&gt; 30.18 in. Hg (1022 hPa)&lt;/Pressure&gt; 
    &lt;Status&gt;Success&lt;/Status&gt; 
&lt;/CurrentWeather&gt;</GetWeatherResult></GetWeatherResponse></soap:Body></soap:Envelope>" 
; compiling (DEFUN CREATE-BODY-FOR-REQUEST-GET-WEATHER-SOAP12 ...) 
; compiling (DEFUN SEND-SOAP12-REQUEST ...) 
CL-USER> answer 

#(60 63 120 109 108 32 118 101 114 115 105 111 110 61 34 49 46 48 34 32 101 110 
    99 111 100 105 110 103 61 34 117 116 102 45 56 34 63 62 60 115 111 97 112 58 
    69 110 118 101 108 111 112 101 32 120 109 108 110 115 58 115 111 97 112 61 34 
    104 116 116 112 58 47 47 119 119 119 46 119 51 46 111 114 103 47 50 48 48 51 
    47 48 53 47 115 111 97 112 45 101 110 118 101 108 111 112 101 34 32 120 109 
    108 110 115 58 120 115 105 61 34 104 116 116 112 58 47 47 119 119 119 46 119 
    51 46 111 114 103 47 50 48 48 49 47 88 77 76 83 99 104 101 109 97 45 105 110 
    115 116 97 110 99 101 34 32 120 109 108 110 115 58 120 115 100 61 34 104 116 
    116 112 58 47 47 119 119 119 46 119 51 46 111 114 103 47 50 48 48 49 47 88 77 
    76 83 99 104 101 109 97 34 62 60 115 111 97 112 58 66 111 100 121 62 60 71 
    101 116 87 101 97 116 104 101 114 82 101 115 112 111 110 115 101 32 120 109 
    108 110 115 61 34 104 116 116 112 58 47 47 119 119 119 46 119 101 98 115 101 
    114 118 105 99 101 88 46 78 69 84 34 62 60 71 101 116 87 101 97 116 104 101 
    114 82 101 115 117 108 116 62 38 108 116 59 63 120 109 108 32 118 101 114 115 
    105 111 110 61 34 49 46 48 34 32 101 110 99 111 100 105 110 103 61 34 117 116 
    102 45 49 54 34 63 38 103 116 59 13 10 38 108 116 59 67 117 114 114 101 110 
    116 87 101 97 116 104 101 114 38 103 116 59 13 10 32 32 38 108 116 59 76 111 
    99 97 116 105 111 110 38 103 116 59 86 97 108 101 110 99 105 97 32 47 32 65 
    101 114 111 112 117 101 114 116 111 44 32 83 112 97 105 110 32 40 76 69 86 67 
    41 32 51 57 45 51 48 78 32 48 48 48 45 50 56 87 32 54 50 77 38 108 116 59 47 
    76 111 99 97 116 105 111 110 38 103 116 59 13 10 32 32 38 108 116 59 84 105 
    109 101 38 103 116 59 74 117 110 32 48 55 44 32 50 48 49 54 32 45 32 48 54 58 
    51 48 32 65 77 32 69 68 84 32 47 32 50 48 49 54 46 48 54 46 48 55 32 49 48 51 
    48 32 85 84 67 38 108 116 59 47 84 105 109 101 38 103 116 59 13 10 32 32 38 
    108 116 59 87 105 110 100 38 103 116 59 32 102 114 111 109 32 116 104 101 32 
    69 32 40 48 56 48 32 100 101 103 114 101 101 115 41 32 97 116 32 57 32 77 80 
    72 32 40 56 32 75 84 41 32 40 100 105 114 101 99 116 105 111 110 32 118 97 
    114 105 97 98 108 101 41 58 48 38 108 116 59 47 87 105 110 100 38 103 116 59 
    13 10 32 32 38 108 116 59 86 105 115 105 98 105 108 105 116 121 38 103 116 59 
    32 103 114 101 97 116 101 114 32 116 104 97 110 32 55 32 109 105 108 101 40 
    115 41 58 48 38 108 116 59 47 86 105 115 105 98 105 108 105 116 121 38 103 
    116 59 13 10 32 32 38 108 116 59 83 107 121 67 111 110 100 105 116 105 111 
    110 115 38 103 116 59 32 109 111 115 116 108 121 32 99 108 101 97 114 38 108 
    116 59 47 83 107 121 67 111 110 100 105 116 105 111 110 115 38 103 116 59 13 
    10 32 32 38 108 116 59 84 101 109 112 101 114 97 116 117 114 101 38 103 116 
    59 32 55 56 32 70 32 40 50 54 32 67 41 38 108 116 59 47 84 101 109 112 101 
    114 97 116 117 114 101 38 103 116 59 13 10 32 32 38 108 116 59 68 101 119 80 
    111 105 110 116 38 103 116 59 32 53 55 32 70 32 40 49 52 32 67 41 38 108 116 
    59 47 68 101 119 80 111 105 110 116 38 103 116 59 13 10 32 32 38 108 116 59 
    82 101 108 97 116 105 118 101 72 117 109 105 100 105 116 121 38 103 116 59 32 
    52 55 37 38 108 116 59 47 82 101 108 97 116 105 118 101 72 117 109 105 100 
    105 116 121 38 103 116 59 13 10 32 32 38 108 116 59 80 114 101 115 115 117 
    114 101 38 103 116 59 32 51 48 46 49 56 32 105 110 46 32 72 103 32 40 49 48 
    50 50 32 104 80 97 41 38 108 116 59 47 80 114 101 115 115 117 114 101 38 103 
    116 59 13 10 32 32 38 108 116 59 83 116 97 116 117 115 38 103 116 59 83 117 
    99 99 101 115 115 38 108 116 59 47 83 116 97 116 117 115 38 103 116 59 13 10 
    38 108 116 59 47 67 117 114 114 101 110 116 87 101 97 116 104 101 114 38 103 
    116 59 60 47 71 101 116 87 101 97 116 104 101 114 82 101 115 117 108 116 62 
    60 47 71 101 116 87 101 97 116 104 101 114 82 101 115 112 111 110 115 101 62 
    60 47 115 111 97 112 58 66 111 100 121 62 60 47 115 111 97 112 58 69 110 118 
    101 108 111 112 101 62) 
CL-USER> (format nil "~{~A~}" (map 'list #'(lambda (value) (code-char value)) answer)) 
"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body><GetWeatherResponse xmlns=\"http://www.webserviceX.NET\"><GetWeatherResult>&lt;?xml version=\"1.0\" encoding=\"utf-16\"?&gt; 
&lt;CurrentWeather&gt; 
    &lt;Location&gt;Valencia/Aeropuerto, Spain (LEVC) 39-30N 000-28W 62M&lt;/Location&gt; 
    &lt;Time&gt;Jun 07, 2016 - 06:30 AM EDT/2016.06.07 1030 UTC&lt;/Time&gt; 
    &lt;Wind&gt; from the E (080 degrees) at 9 MPH (8 KT) (direction variable):0&lt;/Wind&gt; 
    &lt;Visibility&gt; greater than 7 mile(s):0&lt;/Visibility&gt; 
    &lt;SkyConditions&gt; mostly clear&lt;/SkyConditions&gt; 
    &lt;Temperature&gt; 78 F (26 C)&lt;/Temperature&gt; 
    &lt;DewPoint&gt; 57 F (14 C)&lt;/DewPoint&gt; 
    &lt;RelativeHumidity&gt; 47%&lt;/RelativeHumidity&gt; 
    &lt;Pressure&gt; 30.18 in. Hg (1022 hPa)&lt;/Pressure&gt; 
    &lt;Status&gt;Success&lt;/Status&gt; 
&lt;/CurrentWeather&gt;</GetWeatherResult></GetWeatherResponse></soap:Body></soap:Envelope>" 
CL-USER> 
+0

이것은 환상적인 설명이었고, 나를 위해 약간의 재료를 정말로 정리했다! 나는 SOAP을 단순화하는 방법을 특히 좋아했다. (HTTP를 보내고 돌려주는 POST 메서드). 단지 후속 조치로 byte-stream이 ascii라고 추측 했습니까? 어떻게 변환했는지 어떻게 알았습니까? – ajivani

+1

음, 아마도이 단순화는 약간 과장되어 있지만 작동합니다. 두 번째 질문에서, 그것은 직감의 문제였습니다. 나는 배열의 부호없는 문자 클래스를 사용하므로 보통 ASCII 문자를 의미하지만 Base 10에 있으므로 기본 16 진수로 전달한 다음 문자로 변환합니다. 그러나 이것은 api, 또는 사용 된 charset 이게 도움이 된 것을 기쁘게 생각합니다 – anquegi

-1

를 사용하여 UTF-8 인코딩 없습니다 :

(ppcre:regex-replace-all (format nil "~c" #\Return) (flexi-streams:octets-to-string response :external-format :utf-8) ""))) 
+0

솔루션에서 대체 할 라인이 흥미 롭습니다. 끝 부분에 가까운이 하나가 변환되는 곳이 좋습니까? 여기에 하나 : "(형식 nil"~ {~ A ~} "(지도 '목록 #'(람다 (값) (코드 - char 값)))) 또는 다른 곳으로 변경 하시겠습니까? – ajivani

관련 문제