Сервис калькулятор. WSDL-файл. Порт
Сервисориентир-
ованная 1 <wsdl:portType name="Calculator">
архитектура. Фрэймворк 2
Axis2/C
3 <wsdl:operation name="add">
Данилов И.
Г.4
ассистент
каф. МОП 5 <wsdl:input message="impl:addRequest" name="
ЭВМ
addRequest"/>
6
7 <wsdl:output message="impl:addResponse" name=" addResponse"/>
8
9 </wsdl:operation>
10
11 </wsdl:portType>
31 / 42
Сервис калькулятор. WSDL-файл. Связывание
Сервисориентированная архитектура. Фрэймворк Axis2/C
Данилов И. Г.
ассистент каф. МОП ЭВМ
1 |
<wsdl:binding name="CalculatorSoapBinding" type="impl:Calculator"> |
2 |
|
3 |
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org |
4 |
/soap/http"/> |
|
|
5 |
<wsdl:operation name="add"> |
6 |
|
7 |
<wsdlsoap:operation soapAction="Calculator#add"/> |
8 |
|
9 |
<wsdl:input name="addRequest"> |
10 |
<wsdlsoap:body use="literal"/> |
11 |
</wsdl:input> |
12 |
|
13 |
<wsdl:output name="addResponse"> |
14 |
<wsdlsoap:body use="literal"/> |
15 |
</wsdl:output> |
16 |
|
17 |
</wsdl:operation> |
18 |
|
19 |
</wsdl:binding> |
|
|
32 / 42
Сервис калькулятор. WSDL-файл. Объявление сервиса
Сервисориентированная архитектура. Фрэймворк Axis2/C
Данилов И. Г.
ассистент каф. МОП ЭВМ
1 |
<wsdl:service name="Calculator"> |
2 |
|
3 |
<wsdl:port binding="impl:CalculatorSoapBinding" |
|
name="Calculator"> |
4 |
|
5 |
<wsdlsoap:address location="http://localhost/ |
|
axis/Calculator"/> |
6 |
|
7 |
</wsdl:port> |
8 |
|
9 |
</wsdl:service> |
|
|
33 / 42
Генерируем файлы заглушек
Сервисориентированная архитектура. Фрэймворк Axis2/C
Данилов И. Г.
ассистент каф. МОП ЭВМ
Сервис
$ WSDL2C.sh -uri calculator.wsdl -ss -sd -d adb -u
...
$ ls
adb_add.c adb_addResponse.c axis2_extension_mapper.c axis2_skel_Calculator.c axis2_svc_skel_Calculator.c adb_add.h adb_addResponse.h axis2_extension_mapper.h axis2_skel_Calculator.h services.xml
Клиент
$ WSDL2C.sh -uri calculator.wsdl -d adb -u
34 / 42
Файл service.xml
Сервис- |
|
|
ориентир- |
|
|
ованная |
|
|
архитектура. |
1 |
<?xml version="1.0" encoding="UTF 8"?> |
Фрэймворк |
||
Axis2/C |
2 |
|
Данилов И. |
3 |
<! This file was auto generated from WSDL > |
Г.4 <! by the Apache Axis2 version: 1.6.2 Built on : Apr 17, 2012 (05:33:49 IST)
ассистент |
|
> |
|
каф. МОП |
5 |
||
ЭВМ |
|
||
6 |
<service name="Calculator"> |
||
|
|||
|
7 |
<parameter name="ServiceClass">Calculator</parameter> |
|
|
8 |
|
|
|
9 |
<description>Calculator Service</description> |
|
|
10 |
<operation name="add" mep="http://www.w3.org/ns/wsdl/in out"> |
|
|
11 |
||
|
12 |
<parameter name="wsamapping">Calculator#add</parameter> |
|
|
13 |
</operation> |
|
|
14 |
</service> |
35 / 42
Реализуем axis2_svc_skel_Calculator.c
Сервисориентированная архитектура. Фрэймворк Axis2/C
Данилов И. Г.
ассистент каф. МОП ЭВМ
1 |
axiom_node_t AXIS2_CALL axis2_svc_skel_Calculator_invoke |
|||
2 |
( . . . ) |
|
|
|
{ |
|
|
|
|
3 |
. . . |
|
|
|
4 |
adb_addResponse_t ret_val2 ; |
|
||
5 |
adb_add_t input_val2 ; |
|
||
6 |
. . . |
|
|
|
7 |
i f ( op_name ) { |
|
|
|
8 |
i f ( |
axutil_strcmp ( op_name , "add" ) |
== 0 ) { |
|
9 |
i f ( |
AXIS2_FAILURE == adb_add_deserialize ( input_val2 |
||
10 |
|
, env , |
&content_node , NULL , |
AXIS2_FALSE ) ) { |
. . . |
|
|
||
11 |
} |
|
|
|
12 |
. . . |
|
|
|
13 |
ret_val2 = |
axis2_skel_Calculator_add ( env , msg_ctx , |
||
14 |
. . . |
input_val2 ) ; |
|
|
|
|
|
||
15 |
ret_node = |
adb_addResponse_serialize ( ret_val2 , env , |
||
16 |
. . . |
NULL , |
NULL , AXIS2_TRUE , NULL , NULL ) ; |
|
|
|
|
||
17 |
r e t u r n ret_node ; |
|
||
|
|
|
|
|
36 / 42
Реализуем axis2_skel_Calculator.c
Сервисориентированная архитектура. Фрэймворк Axis2/C
Данилов И. Г.
ассистент каф. МОП ЭВМ
1 |
adb_addResponse_t axis2_skel_Calculator_add ( cons t |
||||
|
axutil_env_t env , |
axis2_msg_ctx_t msg_ctx , |
|||
2 |
adb_add_t _add ) |
{ |
|
||
|
|
|
|
|
|
3 |
adb_addResponse_t |
add_res = NULL ; |
|||
4 |
i n t |
ret_val = 0 ; |
|
|
|
5 |
i n t |
val1 = |
0 ; |
|
|
6 |
i n t |
val2 = |
0 ; |
|
|
7 |
|
|
|
|
|
8 |
val1 |
= adb_add_get_arg_0_0 ( _add , env ) ; |
|||
9 |
val2 |
= adb_add_get_arg_1_0 ( _add , env ) ; |
|||
10 |
ret_val = val1 + val2 ; |
||||
11 |
|
|
|
|
|
12 |
add_res = adb_addResponse_create ( env ) ; |
||||
13 |
adb_addResponse_set_addReturn ( add_res , env , ret_val ) ; |
||||
14 |
|
|
|
|
|
15 |
r e t u r n add_res ; |
|
|
||
16 |
} |
|
|
|
|
|
|
|
|
|
|
37 / 42
Структура проекта
Сервисориентированная архитектура. Фрэймворк Axis2/C
Данилов И. Г.
ассистент каф. МОП ЭВМ
service
CMakeLists.txt resources
services.xml
src
...
38 / 42
CMakeLists.txt
Сервис- |
1 |
|
|
|
|
|
ориентир- |
cmake_minimum_required ( VERSION 2 . 6 ) |
|||||
ованная |
2 |
|
|
|
|
|
архитектура. |
set ( PROJECT Calculator ) |
|||||
Фрэймворк |
3 |
|||||
Axis2/C |
4 |
|
|
|
|
|
Данилов И. |
5 |
file ( GLOB |
HEADERS |
" . / s r c / . h" ) |
||
Г. |
6 |
file ( GLOB |
SOURCES |
" . / s r c / . c" ) |
||
ассистент |
7 |
|
|
|
|
|
каф. МОП |
8 |
set ( LIBRARIES axutil axis2_axiom axis2_parser |
||||
ЭВМ |
||||||
|
axis2_engine axis2_http_sender axis2_http_receiver |
|||||
|
|
|||||
|
9 |
guththila pthread ) |
||||
|
|
|
|
|
||
|
10 |
include_directories |
( . / src ) |
|||
|
11 |
include_directories |
( $ENV { AXIS2C_INCLUDE }) |
|||
|
12 |
include_directories ( $ENV { AXIS2C_INCLUDE }/ platforms ) |
||||
|
13 |
|
|
|
|
|
|
14 |
link_directories ( $ENV { AXIS2C_HOME }/ lib ) |
||||
|
15 |
|
|
|
|
|
|
16 |
add_library ( ${ PROJECT } SHARED ${ HEADERS } ${ SOURCES }) |
||||
|
17 |
|
|
|
|
|
|
18 |
target_link_libraries ( ${ PROJECT } ${ LIBRARIES }) |
||||
|
|
|
|
|
|
39 / 42
Клиент, функция main
Сервисориентированная архитектура. Фрэймворк Axis2/C
Данилов И. Г.
ассистент каф. МОП ЭВМ
1 |
endpoint_uri = " http :// l o c a l h o s t :9090/ a x i s 2 / s e r v i c e s / |
|
2 |
|
C a l c u l a t o r " ; |
env |
= axutil_env_create_all ( " a l l t e s t . l o g " , |
|
3 |
|
AXIS2_LOG_LEVEL_TRACE ) ; |
|
|
|
4 |
client_home = AXIS2_GETENV ( "AXIS2C_HOME" ) ; |
|
5 |
|
|
6 |
stub |
= axis2_stub_create_Calculator ( env , client_home , |
|
|
endpoint_uri ) ; |
7add_in = adb_add_create ( env ) ;
8 adb_add_set_arg_0_0 ( add_in , env , 10) ;
9adb_add_set_arg_1_0 ( add_in , env , 10) ;
10 |
add_res = axis2_stub_op_Calculator_add ( stub , env , |
11 |
add_in ) ; |
i f ( ! add_res ) { |
|
12 |
printf ( " E r r o r : r e s p o n s e NULL\n" ) ; |
13 |
r e t u r n 1; |
14}
15 res_val = adb_addResponse_get_addReturn ( add_res , env ) ;
16 |
printf ( "ADD R e s u l t :%d\n" , res_val ) ; |
40 / 42