官网文档: http://axis.apache.org/axis2/c/core/docs/axis2c_manual.html
从文档中可以总结出:
1. Axis2/C是一个用C语言实现的Web Service引擎。
Axis2/C基于Axis2架构,支持SOAP1.1和SOAP1.2协议,并且支持RESTful风格的Web Service。基于Axis2/C的Web Service可以同时暴露为SOAP和RESTful风格的服务。
2. 构建Axis2/c服务的基本步骤:
*Implement the functions corresponding to the operations of the service.
In our sample, we will have one function that implements the "greet" operation.
We will name that function axis2_hello_greet
.
*Implement the functions defined by the axis2_svc_skeleton
interface
axis2_svc_skeleton
interface expects the functions init
, invoke
, on_fault
and free
to be implemented by our service.
In our sample, we would implement those and name them as hello_init
, hello_invoke
, hello_on_fault
and hello_free
respectively.
* Implement the create function, that would create an instance of the service skeleton
The create function would create an axis2_svc_skeleton and assign the respective function pointers to map the axis2_svc_skeleton interface to our interface implementation methods explained in the above step.
* Implement axis2_get_instance and axis2_remove_instance functions
These functions are used to create and destroy service instances by the engine, and each service must define these functions.
* Write the services.xml file for the service
The services.xml file acts as the deployment descriptor file for the service. As the bare minimum, we need to configure the service name, operations, and the shared library file name containing the service implementation in this file.
As previously decided, we will name the service "hello", the operation "greet" and the shared library libhello.so on Linux and hello.dll on MS Windows.
3. Server API (官网文档)
4. REST 实现(官网文档)
编译命令:
gcc -shared -fPIC -o libhello.so -I$AXIS2C_HOME/include/axis2-1.6.0/ -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -laxis2_engine -lpthread -laxis2_http_sender -laxis2_http_receiver hello.c
构造XML
例如:
axis2_hello_getconfig(const axutil_env_t *env, axiom_node_t *node)
{
axiom_node_t* root_node_t = NULL;
axiom_node_t* node_value = NULL;
axiom_node_t* node_type = NULL;
axiom_element_t * ele_root = NULL;
axiom_element_t * ele_value = NULL;
axiom_element_t * ele_type = NULL;
ele_root = axiom_element_create(env, NULL, "Config", NULL, &root_node_t);
ele_value = axiom_element_create(env, root_node_t, "value", NULL, &node_value);
axiom_element_set_text(ele_value, env, "88", node_value);
ele_type = axiom_element_create(env, root_node_t, "type", NULL, &node_type);
axiom_element_set_text(ele_type, env, "get", node_type);
return root_node_t;
}