我正在使用 C++ 中的 Apache axis2c 开发 SOAP Web 服务。我使用 services.xml
设置一些特定于服务的参数,我需要在 axis2_svc_skeleton
接口(interface)中获取这些参数的值(例如在 axis2_get_instance
函数中).但是我不知道我该怎么做?
这是我的 services.xml 的一部分,我想在我的代码中访问 myreadonlyparam
的值:
<service name="myservice">
<parameter name="myreadonlyparam" locked="xsd:true">myparamvalue</parameter>
...
</service>
这是我的代码的一部分
AXIS2_EXPORT int axis2_get_instance( axis2_svc_skeleton_t ** inst, const axutil_env_t * env )
{
*inst = axis2_myservice_create(env);
if (!(*inst))
{
return AXIS2_FAILURE;
}
//HERE I NEED SERVICE PARAMETER VALUE
...
}
有什么想法吗?
最佳答案
如果没有 axis2_conf
对象,恐怕无法获取服务配置。 axis2_conf
对象只能在 init_with_conf
函数中访问。
服务参数获取示例:
int AXIS2_CALL my_service_init_with_conf(
axis2_svc_skeleton_t* skel, const axutil_env_t* env, axis2_conf* conf)
{
const axis2_char_t* service_name = "myservice";
/* get service by name */
struct axis2_svc* service = axis2_conf_get_svc(conf, env, service_name);
/* get service param */
axutil_param_t* param = axis2_svc_get_param(service, env, "myreadonlyparam");
/* get param value */
const char* value = (const char*) axutil_param_get_value(param, env);
printf("PARAM VALUE: %s\n", value);
return AXIS2_SUCCESS;
}
/* Skeleton options */
static axis2_svc_skeleton_ops_t skel_ops =
{
my_service_init,
my_service_invoke,
my_service_on_fault,
my_service_free,
my_service_init_with_conf
};
AXIS2_EXPORT int axis2_get_instance(
axis2_svc_skeleton** skel, axutil_env_t* env)
{
*skel = (axis2_svc_skeleton_t*) AXIS2_MALLOC(
env->allocator, sizeof(axis2_svc_skeleton_t));
if (!*skel)
return AXIS2_FAILURE;
(*skel)->ops = &skel_ops;
(*skel)->func_array = NULL;
return AXIS2_SUCCESS;
}
输出:
$ ./axis2_http_server PARAM VALUE: myparamvalue Started Simple Axis2 HTTP Server ...
关于c++ - 使用 axis2c 开发 Web 服务时如何访问轴骨架代码中的服务参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21705974/