• JAVA Client call gSOAP server


    Hi,

    I am trying to write a java client (using Axis) to call a webservice
    written in C++ using gsoap.
    I am passing a string of type "String" through the java client. At
    the gsoap the declaration is "char ".

    Surprisingly, values in c++ webservice are coming null even though I
    am passing some value from the java client. Please let me know what
    could be the reason.

    I am not getting any exception at Java client side. The C++ web service is
    in the form of a CGI.

    Here is the some part of the C++ web service and the Java client.

    final String endPoint = "http://abc.xyz.com/Profile.cgi";

    final String AddMethod = "AddBuyer";


    String AddNewBuyerProfile( String name1Str,

    String name2Str,

    String address1Str,

    String cityStr,

    String stateStr,

    String countryStr,

    String postalCodeStr,

    String emailStr,

    String telephoneStr,

    String accessNameStr,

    String genderStr,

    String challengeQStr ,

    String challengeAStr )

    {


    String errorStr = "";

    int errorCode = 99;

    int result = 99;


    try

    {

    Service service = new Service();

    Call call = (Call) service.createCall();


    call.setTargetEndpointAddress( new java.net.URL(endPoint) );

    call.setOperationName(new QName("http://tempuri.org/ns1.xsd", AddMethod));

    call.removeAllParameters();


    call.addParameter("name1_str", org.apache.axis.Constants.XSD_STRING, javax.xml.rpc.ParameterMode.IN); //1


    call.addParameter("name2_str", org.apache.axis.Constants.XSD_STRING, javax.xml.rpc.ParameterMode.IN); //2

    ....

    ....


    call.setReturnType(org.apache.axis.Constants.XSD_INTEGER);



    String retStr = (String) call.invoke( new Object[] {

    name1Str, //1

    name2Str, //2

    address1Str, //3

    cityStr, //4

    stateStr, //5

    countryStr, //6

    postalCodeStr, //7

    emailStr, //8

    telephoneStr, //9

    accessNameStr, //10

    genderStr, //11

    challengeQStr , //12

    challengeQStr , //13

    result //14

    } ) ;


    System.out.println("The response is '" retStr "'");

    int result1 = Integer.parseInt(retStr.trim());


    if ( result1 == INITIALIZE_ERROR)

    {

    errorStr = "Initialization Error. Addition of new buyer failed !!";

    }

    else

    if ( result1 == ADD_ERROR )

    {

    errorStr = "Addition of new buyer failed !!";

    }

    else

    if ( result1 == SUCCESS_CODE )

    {

    errorStr = "Addition of new buyer successful !!";

    }


    }

    catch (Exception e)

    {

    errorStr = e.toString();

    }

    return errorStr;

    }

    AND at the web service declaration is

    cat INC/Server.h
    typedef char *xsd__string; // encode xsd__string value as the xsd:string schema type

    //gsoap ns1 service location: http://abc.xyz.com/Profile.cgi
    int ns1__AddBuyer(xsd__string name1_str, xsd__string name2_str, xsd__string address1_str,xsd__string city_str, xsd__string state_str, xsd__string country_str, xsd__string postalCode_str, xsd__string email_str, xsd__string telephone_str, xsd__string accessName_str, xsd__string gender_char, xsd__string challenge_q, xsd__string challenge_a, int
    &result);

    and the webservice implementation ...

    #include "soapH.h" / include generated proxy and SOAP support /
    #include "ns1.nsmap"
    #include "MainDriver.h"

    int main()
    {
    soap_serve(soap_new()); //// use the remote method request dispatcher

    //or alternatively,
    //struct soap soap;
    //soap_init(&soap);
    //soap_serve(&soap);
    }

    int ns1__AddBuyer(struct soap soap, char *name1_str, char *name2_str, char *address1_str,char *city_str, char *state_str, char *country_str, char *postalCode_str, char *email_str, char *telephone_str, char *accessName_str, char gender_char, char challenge_q, char *challenge_a, int &result)
    {
    cout << telephone_str << endl;
    ............
    }

    and the ns1.nsmap is

    cat ns1.nsmap


    #include "soapH.h"
    SOAP_NMAC struct Namespace namespaces[] =
    {
    {"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org//soap-envelope", NULL},
    {"SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", "http://www.w3.org/
    /soap-encoding", NULL},
    {"xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org//XMLSchema-instance", NULL},
    {"xsd", "http://www.w3.org/2001/XMLSchema", "http://www.w3.org/
    /XMLSchema", NULL},
    {"ns1", "http://tempuri.org/ns1.xsd", NULL, NULL},
    {NULL, NULL, NULL, NULL}
    };


    I appreciate any suggestion to overcome this problem.

    Thanks.

  • 相关阅读:
    基本排序算法汇总
    贪心算法题目汇总
    STL中sort
    栈和队列题目汇总
    cron 计划任务 在线配置
    各种less概念通俗解释
    node 子线程 进程
    内存池
    RPC简介
    koa express 对比
  • 原文地址:https://www.cnblogs.com/cy163/p/1556695.html
Copyright © 2020-2023  润新知