You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@axis.apache.org by Mark Whitlock <ma...@uk.ibm.com> on 2004/12/13 17:58:45 UTC

Example C applications




Hi,
As Nadir asked, here is an example of what the Calculator C sample might
look like using generated C stubs...

#include "Calculator.h"
int main(int argc, char **argv) {
  AXISCHANDLE stub;
  char *endpoint;
  char *op;
  int num1;
  int num2;

  endpoint = argv[1];
  op = argv[2];
  num1 = atoi(argv[3]);
  num2 = atoi(argv[4]);
  stub = axiscCreateCalculatorStub(endpoint);

  if (!strcmp(op,"add")) add(stub,num1,num2);
  else if (!strcmp(op,"sub")) sub(stub,num1,num2);
  else if (!strcmp(op,"mul")) mul(stub,num1,num2);
  else if (!strcmp(op,"div")) div(stub,num1,num2);

  axiscDestroyCalculatorStub(stub);
  return 0;
}

Here is an example of what the Calculator C sample might look like without
using generated C stubs...

#include <axis/client/Stub.h>
#include <axis/AxisException.h>
#include <axis/ISoapFault.h>
#include <axis/AxisUserAPI.h>

int main(int argc, char **argv) {
  AXISCHANDLE call;
  char *endpoint;
  char *op;
  int num1;
  int num2;
  char soapaction[128];
  int ret;
  char *uri = "http://localhost/axis/Calculator";
  int result = 0;

  endpoint = argv[1];
  op = argv[2];
  num1 = atoi(argv[3]);
  num2 = atoi(argv[4]);
  sprintf(soapaction,"Calculator#%s",op);

  call = axiscCreateCall(endpoint,AXISC_APTHTTP);
  ret = axiscInitialize(call, AXISC_C_RPC_PROVIDER, AXISC_NORMAL_CHANNEL);
  if (AXISC_SUCCESS != ret) {
    printf("Failed to initialize\n");
    return -1;
  }

  axiscSetTransportProperty(call, AXISC_SOAPACTION_HEADER, soapaction);
  axiscSetSOAPVersion(call, AXISC_SOAP_VER_1_1);
  axiscSetOperation(call, op, uri);
  axiscAddParameter(call, &num1, "in0", XSD_INT);
  axiscAddParameter(call, &num2, "in1", XSD_INT);

  ret = axiscInvoke(call);
  if (AXISC_SUCCESS == ret) {
    ret = axiscCheckMessage(call, "addResponse", uri);
    if (AXISC_SUCCESS == ret) {
      result = axiscGetElementAsInt(call, "addReturn", 0);
      printf("Calculator %s %d %d returned %d\n", op, num1, num2, result);
    } else printf("Failed to get result\n");
  } else printf("Failed to invoke service\n");

  axiscUninitialize(call);
  axiscDestroyCall(call);
  return 0;
}

Obviously these need comments and better error checking.
Mark
Mark Whitlock
IBM


Re: Example C applications

Posted by Samisa Abeysinghe <sa...@gmail.com>.
Hi Mark,
    I have a question. What is AXISCHANDLE defined to be?
Thanks,
Samisa...


On Mon, 13 Dec 2004 16:58:45 +0000, Mark Whitlock
<ma...@uk.ibm.com> wrote:
> 
> 
> Hi,
> As Nadir asked, here is an example of what the Calculator C sample might
> look like using generated C stubs...
> 
> #include "Calculator.h"
> int main(int argc, char **argv) {
>   AXISCHANDLE stub;
>   char *endpoint;
>   char *op;
>   int num1;
>   int num2;
> 
>   endpoint = argv[1];
>   op = argv[2];
>   num1 = atoi(argv[3]);
>   num2 = atoi(argv[4]);
>   stub = axiscCreateCalculatorStub(endpoint);
> 
>   if (!strcmp(op,"add")) add(stub,num1,num2);
>   else if (!strcmp(op,"sub")) sub(stub,num1,num2);
>   else if (!strcmp(op,"mul")) mul(stub,num1,num2);
>   else if (!strcmp(op,"div")) div(stub,num1,num2);
> 
>   axiscDestroyCalculatorStub(stub);
>   return 0;
> }
> 
> Here is an example of what the Calculator C sample might look like without
> using generated C stubs...
> 
> #include <axis/client/Stub.h>
> #include <axis/AxisException.h>
> #include <axis/ISoapFault.h>
> #include <axis/AxisUserAPI.h>
> 
> int main(int argc, char **argv) {
>   AXISCHANDLE call;
>   char *endpoint;
>   char *op;
>   int num1;
>   int num2;
>   char soapaction[128];
>   int ret;
>   char *uri = "http://localhost/axis/Calculator";
>   int result = 0;
> 
>   endpoint = argv[1];
>   op = argv[2];
>   num1 = atoi(argv[3]);
>   num2 = atoi(argv[4]);
>   sprintf(soapaction,"Calculator#%s",op);
> 
>   call = axiscCreateCall(endpoint,AXISC_APTHTTP);
>   ret = axiscInitialize(call, AXISC_C_RPC_PROVIDER, AXISC_NORMAL_CHANNEL);
>   if (AXISC_SUCCESS != ret) {
>     printf("Failed to initialize\n");
>     return -1;
>   }
> 
>   axiscSetTransportProperty(call, AXISC_SOAPACTION_HEADER, soapaction);
>   axiscSetSOAPVersion(call, AXISC_SOAP_VER_1_1);
>   axiscSetOperation(call, op, uri);
>   axiscAddParameter(call, &num1, "in0", XSD_INT);
>   axiscAddParameter(call, &num2, "in1", XSD_INT);
> 
>   ret = axiscInvoke(call);
>   if (AXISC_SUCCESS == ret) {
>     ret = axiscCheckMessage(call, "addResponse", uri);
>     if (AXISC_SUCCESS == ret) {
>       result = axiscGetElementAsInt(call, "addReturn", 0);
>       printf("Calculator %s %d %d returned %d\n", op, num1, num2, result);
>     } else printf("Failed to get result\n");
>   } else printf("Failed to invoke service\n");
> 
>   axiscUninitialize(call);
>   axiscDestroyCall(call);
>   return 0;
> }
> 
> Obviously these need comments and better error checking.
> Mark
> Mark Whitlock
> IBM
> 
>