Axis2C。客户端无法连接到 Web 服务器

问题描述 投票:0回答:0

论坛全体成员大家好

我叫何塞普。 我是一名计算机工程师,但我以前没有使用过轴 2。 我想提出我的问题,看看是否有人可以帮助我。 (提前致谢) [我在论坛和谷歌上搜索了以前的消息,但找不到解决方案。]

我正在创建一个代码以作为客户端连接到 Web 服务。 (只有客户端服务器在另一台机器上,已经可以工作了) [我从一个 ECHO 示例开始我的代码。我在 https://github.com/bnoordhuis/axis2-c/blob/master/samples/client/echo/echo.c 找到它]

我创建一个请求。我发送了它,但没有得到答复。 同样的请求,我在 SOAP ui 中执行它并且它工作正常。 我怀疑这是身份验证的问题,但我不知道还能证明什么。

函数axis2_svc_client_send_receive()返回NULL。 而且,在 C 轴日志中,这个错误:


[Thu Jan 16 17:56:01 2020] [info]  Starting addressing out handler
[Thu Jan 16 17:56:01 2020] [debug] ..\..\src\modules\mod_addr\addr_out_handler.c(133) No action present. Stop processing addressing
[Thu Jan 16 17:56:01 2020] [debug] ..\..\src\core\transport\http\sender\http_transport_sender.c(246) ctx_epr:http://XXXXXXXXXXXXXXXXXXXXXXX/CustomerInstanceWS?wsdl
[Thu Jan 16 17:56:01 2020] [debug] ..\..\src\core\transport\http\sender\http_transport_sender.c(805) using axis2 native http sender.
[Thu Jan 16 17:56:01 2020] [debug] ..\..\src\core\transport\http\sender\http_sender.c(416) msg_ctx_id:xxxxxxxxxxxxxxxxxxxxxxxxx
[Thu Jan 16 17:56:01 2020] [error] ..\..\src\core\transport\http\sender\http_client.c(667) Content-Type header missing in HTTP response
[Thu Jan 16 17:56:01 2020] [error] ..\..\src\core\transport\http\sender\http_client.c(668) Response does not contain Content-Type
[Thu Jan 16 17:56:01 2020] [error] ..\..\src\core\transport\http\sender\http_client.c(667) Content-Type header missing in HTTP response
[Thu Jan 16 17:56:01 2020] [error] ..\..\src\core\transport\http\sender\http_client.c(668) Response does not contain Content-Type
[Thu Jan 16 17:56:01 2020] [error] ..\..\src\core\transport\http\sender\http_sender.c(1381) status_code < 0
[Thu Jan 16 17:56:01 2020] [error] ..\..\src\core\engine\engine.c(179) Transport sender invoke failed
[Thu Jan 16 17:56:01 2020] [error] d:\tes.cpp(240) Stub invoke FAILED: Error code: 91 :: Content-Type header missing in HTTP response.

我把我的代码复制到这里(发布时我把地址改成了XXX)



// tes.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include "axis2_stub_CustomerInstanceWS.h"


#include <stdio.h>
#include <axiom.h>
#include <axis2_util.h>
#include <axiom_soap.h>
#include <axis2_client.h>

/* build SOAP request message content using OM */
axiom_node_t* build_om_payload_for_echo_svc(const axutil_env_t *env, int customerId)
{
                //Declaracion de variables
                axis2_char_t *om_str = NULL;
                axiom_namespace_t* soapenv = NULL;
                axiom_namespace_t* es = NULL;
                axiom_namespace_t* es1 = NULL;

                axiom_node_t* envelope_node = NULL;
                axiom_element_t* envelope_ele = NULL;

                axiom_node_t* header_node = NULL;
                axiom_element_t* header_ele = NULL;

                axiom_node_t* body_node = NULL;
                axiom_element_t* body_ele = NULL;

                axiom_node_t* getCustomerData_node = NULL;
                axiom_element_t* getCustomerData_ele = NULL;

                axiom_node_t* getCustomerDataCriteria_node = NULL;
                axiom_element_t* getCustomerDataCriteria_ele = NULL;

                axiom_node_t* customerId_node = NULL;
                axiom_element_t* customerId_ele = NULL;

                //Preparamos los Namespaces
                soapenv = axiom_namespace_create(env, "http://XXXXXXXXXXXXXXXXXXXXXXXXXX/", "soapenv");
                es = axiom_namespace_create(env, "http://XXXXXXXXXXXXXXXXXXXXXXXXXX/", "es");
                es1 = axiom_namespace_create(env, "http://XXXXXXXXXXXXXXXXXXXXXXXXXX/", "es1");

                //Preparamos los parametros
                char Char_customerId[20];
                sprintf(Char_customerId, "%d", customerId);

                //Construimos el REQUEST
                envelope_ele = axiom_element_create(env, NULL, "Envelope", soapenv, &envelope_node);
                header_ele = axiom_element_create(env, envelope_node, "Header", soapenv, &header_node);
                body_ele = axiom_element_create(env, envelope_node, "Body", soapenv, &body_node);
                getCustomerData_ele = axiom_element_create(env, body_node, "getCustomerData", es, &getCustomerData_node);
                getCustomerDataCriteria_ele = axiom_element_create(env, getCustomerData_node, "getCustomerDataCriteria", NULL, &getCustomerDataCriteria_node);
                customerId_ele = axiom_element_create(env, getCustomerDataCriteria_node, "customerId", es1, &customerId_node);

                //Seteamos parametros para la peticion
                axiom_element_set_text(customerId_ele, env, Char_customerId, customerId_node);

                om_str = axiom_node_to_string(envelope_node, env);

                if (om_str)
                {
                               printf("\nSending OM : %s\n", om_str);
                               AXIS2_FREE(env->allocator, om_str);
                               om_str = NULL;
                }
                return envelope_node;
}

int main()
{
                axutil_env_t* env = NULL;
                env = axutil_env_create_all("CustomerInstance.log", AXIS2_LOG_LEVEL_TRACE);

                axis2_char_t* address = "http://XXXXXXXXXXXXXX/CustomerInstanceWS?wsdl";

                /* Create EPR with given address */
                axis2_endpoint_ref_t* endpoint_ref;
                endpoint_ref = axis2_endpoint_ref_create(env, address);

                /* Setup options */
                axis2_options_t* options_1;
                options_1 = axis2_options_create(env);
                axis2_options_set_to(options_1, env, endpoint_ref);

                ///* Set the deploy folder */
                axis2_char_t* client_home = NULL;
                client_home = AXIS2_GETENV("AXIS2C_HOME");
                if (!client_home)
                {
                               client_home = "../../deploy";
                }

                //* Create service client */
                axis2_svc_client_t* svc_client;
                svc_client = axis2_svc_client_create(env, client_home);
                if (!svc_client)
                {
                               printf("Error creating service client\n");
                               AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Stub invoke FAILED: Error code : %d :: %s", env->error->error_number, AXIS2_ERROR_GET_MESSAGE(env->error));
                }

                //JFI testeamos con esta funcion la AUTENTICACION en el Web Service.
                axis2_status_t status = axis2_options_set_http_auth_info(options_1, env, "C3POxyz", "Admin", "Basic");
                printf("INTENTO DE AUTENTICACION!!!!. Retorno status <%d>\n", status);

                ///* Set service client options */
                axis2_svc_client_set_options(svc_client, env, options_1);

                axiom_node_t* payload;
                payload = build_om_payload_for_echo_svc(env, 2);

                ///* Send request */
                axiom_node_t* ret_node;
                ret_node = axis2_svc_client_send_receive(svc_client, env, payload);

                ///* Print result */
                if (ret_node)
                {
                               axis2_char_t *om_str = NULL;
                               om_str = axiom_node_to_string(ret_node, env);
                               if (om_str)
                               {
                                               printf("\nReceived OM : %s\n", om_str);
                               }
                               printf("\necho client invoke SUCCESSFUL!\n");
                }
                else
                {
                               AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Stub invoke FAILED: Error code: %d :: %s.", env->error->error_number, AXIS2_ERROR_GET_MESSAGE(env->error));
                               printf("echo client invoke FAILED!\n");
                }

                return 0;
}

你看错了吗?给我留了一步?

c authentication web-services axis2
© www.soinside.com 2019 - 2024. All rights reserved.