Hi,
Attached the sample C client .
Rgds,
Ramesh
--- On Wed, 25/3/09, Samisa Abeysinghe <[email protected]> wrote:
> From: Samisa Abeysinghe <[email protected]>
> Subject: Re: How do I embed code to add soap:Envelope and soap:Body within a
> C client ???
> To: "Apache AXIS C User List" <[email protected]>
> Date: Wednesday, 25 March, 2009, 6:50 PM
> Can you please send the full client
> code that you are using?
>
> Samisa...
>
> ramesh Gopal wrote:
> > Hi,
> >
> > I am wanting to consume a web service
> (GetPrimeNumbers).
> >
> > In order to do this, I have written a sample C code,
> which generates the xml request. However, while sending the
> request, I get an error
> >
> > "System.Web.Services.Protocols.SoapException: Server
> was unable to process request. --->
> System.ArgumentOutOfRangeException: Length cannot be less
> than zero"
> >
> > What could be the reason for this error ?
> >
> > My request node looks like:
> > <ns0:GetPrimeNumbers xmlns:ns0="http://microsoft.com/webservices">
> > <ns0:max>23</ns0:max>
> > </ns0:GetPrimeNumbers>
> >
> > However, I think it should look like :
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
> > xmlns:tns="http://www50.brinkster.com/vbfacileinpt/np"
> xmlns:xs="http://www.w3.org/2001/XMLSchema">
> > <soap:Body>
> > <tns:GetPrimeNumbers>
> > <tns:Max>10</tns:Max>
> > </tns:GetPrimeNumbers>
> > </soap:Body>
> > </soap:Envelope>
> >
> > How do I modify the source code to send the soap:body
> and soap:envelope
> >
> > Code listing :
> > --------------
> > tns = axiom_namespace_create(env, "http://microsoft.com/webservices",
> > "tns");
> > echo_om_ele =
> axiom_element_create(env, NULL, "GetPrimeNumbers", tns,
> &echo_om_node);
> > text_om_ele =
> axiom_element_create(env, echo_om_node, "max", tns,
> &text_om_node);
> >
> axiom_element_set_text(text_om_ele, env,
> "10", text_om_node);
> > return echo_om_node;
> >
> >
> > Rgds,
> > Ramesh.
> >
> >
> >
> > Add more friends to
> your messenger and enjoy! Go to http://messenger.yahoo.com/invite/
> >
> >
> ------------------------------------------------------------------------
> >
> >
> > Internal Virus Database is out of date.
> > Checked by AVG - http://www.avg.com
> > Version: 8.0.176 / Virus Database: 270.10.7/1892 -
> Release Date: 1/13/2009 8:04 PM
> >
> >
>
>
> --
> Samisa Abeysinghe
> Director, Engineering; WSO2 Inc.
>
> http://www.wso2.com/ - "The Open Source SOA Company"
>
>
Connect with friends all over the world. Get Yahoo! India Messenger at
http://in.messenger.yahoo.com/?wm=n/#include <stdlib.h>
#include <stdio.h>
#include <axiom.h>
#include <axis2_util.h>
#include <axiom_soap.h>
#include <axis2_client.h>
#include <axis2_msg.h>
axiom_node_t *build_om_request(const axutil_env_t *env, char*);
int test(int nargs)
{
const axutil_env_t *env = NULL;
axis2_char_t *address = NULL;
axis2_endpoint_ref_t* endpoint_ref = NULL;
axis2_options_t *options = NULL;
const axis2_char_t *client_home = NULL;
axis2_svc_client_t* svc_client = NULL;
axis2_svc_t *svc = NULL;
axiom_node_t *payload = NULL;
axiom_node_t *ret_node = NULL;
axiom_node_t *res_node = NULL;
int rc = 0;
axutil_qname_t *svc_qname = NULL;
axutil_qname_t *op_qname = NULL;
axutil_string_t *soap_act = NULL;
const axis2_char_t *soap_action = NULL;
int input0; char inreq0[256] = "\0";;
env = axutil_env_create_all("test_client.log", AXIS2_LOG_LEVEL_TRACE);
soap_action = "http://microsoft.com/webservices/GetPrimeNumbers";
soap_act = axutil_string_create(env,
"http://microsoft.com/webservices/GetPrimeNumbers");
address = "http://www50.brinkster.com/vbfacileinpt/np.asmx";
options = axis2_options_create(env);
endpoint_ref = axis2_endpoint_ref_create(env, address);
client_home = AXIS2_GETENV("AXIS2C_HOME");
axutil_qname_create(env,"PrimeNumbers" ,NULL, NULL);
axis2_svc_set_qname (svc, env, svc_qname);
//stub = axis2_stub_create_with_endpoint_ref_and_client_home ( env,
endpoint_ref, client_home );
axis2_options_set_to(options, env, endpoint_ref);
axis2_options_set_soap_action(options, env, soap_act);
axis2_options_set_action(options, env, soap_action);
axis2_options_set_soap_version(options, env, AXIOM_SOAP11);
//svc_client = axis2_stub_get_svc_client (stub, env );
//svc = (axis2_svc_t*)axis2_svc_client_get_svc( svc_client, env );
svc_client = axis2_svc_client_create(env, client_home);
svc = (axis2_svc_t*)axis2_svc_client_get_svc( svc_client, env );
if (!svc_client)
{
printf("Error creating service client");
return -1;
}
axis2_svc_client_set_options(svc_client, env, options);
if (nargs != 1)
return -1;
/*
op_qname = axutil_qname_create(env,
"GetPrimeNumbers" ,
"http://microsoft.com/webservices/",
NULL);
axis2_op_t *op = axis2_op_create_with_qname(env, op_qname);
axis2_svc_add_op(svc, env, op);
*/
payload = build_om_request(env);
printf ("The value of the input node is %s \n",
axiom_node_to_string(payload, env));
ret_node = axis2_svc_client_send_receive(svc_client, env, payload);
//ret_node = axis2_svc_client_send_receive_with_op_qname( svc_client, env,
op_qname, payload);
if (ret_node)
{
printf ("The value of the node is %s \n",
axiom_node_to_string(ret_node, env));
//const axis2_char_t *greeting = process_om_response(env, ret_node);
axiom_node_free_tree(ret_node, env);
ret_node = NULL;
}
else
{
printf ("Is there some error here \n");
}
if (payload)
{
axiom_node_free_tree(payload, env);
payload = NULL;
}
if (svc_client)
{
axis2_svc_client_free(svc_client, env);
svc_client = NULL;
}
if (env)
{
axutil_env_free((axutil_env_t *) env);
env = NULL;
}
return 1;
}
axiom_node_t * build_om_request(const axutil_env_t *env)
{
axiom_namespace_t *tns = NULL;
axiom_node_t *echo_om_node = NULL;
axiom_element_t* echo_om_ele = NULL;
axiom_node_t* text_om_node = NULL;
axiom_element_t * text_om_ele = NULL;
//axis2_options_t *options = axis2_options_create(env);
//axis2_options_set_soap_version(options, env, AXIOM_SOAP11);
tns = axiom_namespace_create(env, "http://microsoft.com/webservices",
"tns");
echo_om_ele = axiom_element_create(env, NULL, "GetPrimeNumbers", tns,
&echo_om_node);
text_om_ele = axiom_element_create(env, echo_om_node, "max", tns,
&text_om_node);
axiom_element_set_text(text_om_ele, env, "23", text_om_node);
return echo_om_node;
}