免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 11856 | 回复: 12
打印 上一主题 下一主题

gsoap自带的例子,服务端出现“段错误”是什么原因啊?在线等!!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-06-21 17:08 |只看该作者 |倒序浏览
是calc的例子, 我只修改了URL 值:
calcclient.c
/*
        calcclient.c

        Example calculator service client in C

        Compilation in C (see samples/calc/calc.h):
        $ soapcpp2 -c calc.h
        $ cc -o calcclient calcclient.c stdsoap2.c soapC.c soapClient.c

--------------------------------------------------------------------------------
gSOAP XML Web services tools
Copyright (C) 2001-2008, Robert van Engelen, Genivia, Inc. All Rights Reserved.
This software is released under one of the following two licenses:
GPL or Genivia's license for commercial use.
--------------------------------------------------------------------------------
GPL license.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA

Author contact information:
engelen@genivia.com / engelen@acm.org
--------------------------------------------------------------------------------
A commercial use license is available from Genivia, Inc., contact@genivia.com
--------------------------------------------------------------------------------
*/

#include "soapH.h"
#include "calc.nsmap"

//const char server[] = "http://websrv.cs.fsu.edu/~engelen/calcserver.cgi";
const char server[] = "http://10.40.193.23:8888/webtest/calcserver";

int main(int argc, char **argv)
{ struct soap soap;
  double a, b, result;
  if (argc < 4)
  { fprintf(stderr, "Usage: [add|sub|mul|div|pow] num num\n");
    exit(0);
  }
  soap_init(&soap);
  a = strtod(argv[2], NULL);
  b = strtod(argv[3], NULL);
  switch (*argv[1])
  { case 'a':
      soap_call_ns__add(&soap, server, "", a, b, &result);
      break;
    case 's':
      soap_call_ns__sub(&soap, server, "", a, b, &result);
      break;
    case 'm':
      soap_call_ns__mul(&soap, server, "", a, b, &result);
      break;
    case 'd':
      soap_call_ns__div(&soap, server, "", a, b, &result);
      break;
    case 'p':
      soap_call_ns__pow(&soap, server, "", a, b, &result);
      break;
    default:
      fprintf(stderr, "Unknown command\n");
      exit(0);
  }
  if (soap.error)
  { soap_print_fault(&soap, stderr);
    exit(1);
  }
  else
    printf("result = %g\n", result);
  soap_destroy(&soap);
  soap_end(&soap);
  soap_done(&soap);
  return 0;
}



calcserver.c

/*
        calcserver.c

        Example calculator service in C

        Compilation in C (see samples/calc/calc.h):
        $ soapcpp2 -c calc.h
        $ cc -o calcserver calcserver.c stdsoap2.c soapC.c soapServer.c

--------------------------------------------------------------------------------
gSOAP XML Web services tools
Copyright (C) 2001-2008, Robert van Engelen, Genivia, Inc. All Rights Reserved.
This software is released under one of the following two licenses:
GPL or Genivia's license for commercial use.
--------------------------------------------------------------------------------
GPL license.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA

Author contact information:
engelen@genivia.com / engelen@acm.org
--------------------------------------------------------------------------------
A commercial use license is available from Genivia, Inc., contact@genivia.com
--------------------------------------------------------------------------------
*/

#include "soapH.h"
#include "calc.nsmap"

int main(int argc, char **argv)
{ SOAP_SOCKET m, s; /* master and slave sockets */
  struct soap soap;
  soap_init(&soap);
  if (argc < 2)
    soap_serve(&soap);        /* serve as CGI application */
  else
  { m = soap_bind(&soap, NULL, atoi(argv[1]), 100);
    if (!soap_valid_socket(m))
    { soap_print_fault(&soap, stderr);
      exit(-1);
    }
    fprintf(stderr, "Socket connection successful: master socket = %d\n", m);
    for ( ; ; )
    { s = soap_accept(&soap);
      fprintf(stderr, "Socket connection successful: slave socket = %d\n", s);
      if (!soap_valid_socket(s))
      { soap_print_fault(&soap, stderr);
        exit(-1);
      }
     fprintf(stderr, "soap valid socket1\n");
      soap_serve(&soap);
     fprintf(stderr, "soap valid socket2\n");
      soap_end(&soap);
     fprintf(stderr, "soap valid socket3\n");

    }
  }
  return 0;
}

int ns__add(struct soap *soap, double a, double b, double *result)
{ *result = a + b;
  return SOAP_OK;
}

int ns__sub(struct soap *soap, double a, double b, double *result)
{ *result = a - b;
  return SOAP_OK;
}

int ns__mul(struct soap *soap, double a, double b, double *result)
{ *result = a * b;
  return SOAP_OK;
}

int ns__div(struct soap *soap, double a, double b, double *result)
{ if (b)
    *result = a / b;
  else
  { char *s = (char*)soap_malloc(soap, 1024);
    sprintf(s, "<error xmlns=\"http://tempuri.org/\">Can't divide %f by %f</error>", a, b);
    return soap_sender_fault(soap, "Division by zero", s);
  }
  return SOAP_OK;
}

int ns__pow(struct soap *soap, double a, double b, double *result)
{ *result = pow(a, b);
  if (soap_errno == EDOM)        /* soap_errno is like errno, but compatible with Win32 */
  { char *s = (char*)soap_malloc(soap, 1024);
    sprintf(s, "Can't take the power of %f to %f", a, b);
    sprintf(s, "<error xmlns=\"http://tempuri.org/\">Can't take power of %f to %f</error>", a, b);
    return soap_sender_fault(soap, "Power function domain error", s);
  }
  return SOAP_OK;
}


客户端显示:
Error -1 fault: SOAP-ENV:Client [no subcode]
"End of file or no input: Operation interrupted or timed out"
Detail: [no detail]
服务端显示:
Socket connection successful: master socket = 3
Socket connection successful: slave socket = 4
soap valid socket1
段错误


感觉错误是从soap_serve函数中出现的,请教高手是哪里出问题了,谢谢!

论坛徽章:
0
2 [报告]
发表于 2010-06-21 17:41 |只看该作者
哥们儿回去帮你查查。。。如果朝鲜赢的话。。。{:3_189:}

论坛徽章:
0
3 [报告]
发表于 2010-06-21 22:18 |只看该作者
回复 1# blue_sky


    哥们儿可是从网上下载gsoap,重新编译然后再找你的程序错误原因啊,你得谢谢我!

论坛徽章:
0
4 [报告]
发表于 2010-06-21 22:20 |只看该作者
错误原因可能是:

const char server[] = "http://10.40.193.23:8888/webtest/calcserver";
改为
const char server[] = "http://10.40.193.23:8888/";

[root@localhost calc]# ./calcserver 8888
Socket connection successful: master socket = 3
Socket connection successful: slave socket = 4

[root@localhost calc]# ./calcclient add 22 33
result = 55

成功!

论坛徽章:
0
5 [报告]
发表于 2010-06-21 22:20 |只看该作者
哥们儿你也没有在线等啊。。。。

论坛徽章:
0
6 [报告]
发表于 2010-06-23 18:15 |只看该作者
非常感谢rain_fish 的热心解答,可是我用了你的方法,问题依旧,估计是我程序安装或系统环境有问题,我在编译时,显示如下:
../../../gsoap/src/soapcpp2 -cL -I../../../gsoap/import calc.h

**  The gSOAP Stub and Skeleton Compiler for C and C++ 2.7.10
**  Copyright (C) 2000-2008, Robert van Engelen, Genivia Inc.
**  All Rights Reserved. This product is provided "as is", without any warranty.
**  The gSOAP compiler is released under one of the following three licenses:
**  GPL, the gSOAP public license, or the commercial license by Genivia Inc.

Saving soapStub.h
Saving soapH.h
Saving soapC.c
Saving soapClient.c
Saving soapServer.c
Using ns service name: calc
Using ns service style: rpc
Using ns service encoding: encoded
Using ns service location: http://127.0.0.1:8900/
Using ns schema namespace: urn:calc
Saving calc.wsdl Web Service description
Compliance warning: operation 'ns__add' is not compliant with WS-I Basic Profile
1.0a, reason: uses SOAP encoding
Compliance warning: operation 'ns__sub' is not compliant with WS-I Basic Profile
1.0a, reason: uses SOAP encoding
Compliance warning: operation 'ns__mul' is not compliant with WS-I Basic Profile
1.0a, reason: uses SOAP encoding
Compliance warning: operation 'ns__div' is not compliant with WS-I Basic Profile
1.0a, reason: uses SOAP encoding
Compliance warning: operation 'ns__pow' is not compliant with WS-I Basic Profile
1.0a, reason: uses SOAP encoding
Saving calc.add.req.xml sample SOAP/XML request
Saving calc.add.res.xml sample SOAP/XML response
Saving calc.sub.req.xml sample SOAP/XML request
Saving calc.sub.res.xml sample SOAP/XML response
Saving calc.mul.req.xml sample SOAP/XML request
Saving calc.mul.res.xml sample SOAP/XML response
Saving calc.div.req.xml sample SOAP/XML request
Saving calc.div.res.xml sample SOAP/XML response
Saving calc.pow.req.xml sample SOAP/XML request
Saving calc.pow.res.xml sample SOAP/XML response
Saving calc.nsmap namespace mapping table
Saving ns.xsd XML schema

Compilation successful

make  all-am
make[1]: Entering directory `/usr/local/gsoap-2.7/gsoap/samples/calc'
source='calcclient.c' object='calcclient.o' libtool=no \
depfile='.deps/calcclient.Po' tmpdepfile='.deps/calcclient.TPo' \
depmode=gcc3 /bin/sh ../../../depcomp \
gcc -DHAVE_CONFIG_H -I. -I. -I../../.. -I../../../gsoap -I../../../gsoap/plugin
  -DLINUX -g -O2 -c `test -f 'calcclient.c' || echo './'`calcclient.c
source='soapClient.c' object='soapClient.o' libtool=no \
depfile='.deps/soapClient.Po' tmpdepfile='.deps/soapClient.TPo' \
depmode=gcc3 /bin/sh ../../../depcomp \
gcc -DHAVE_CONFIG_H -I. -I. -I../../.. -I../../../gsoap -I../../../gsoap/plugin
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
再附一下calc.h文件:
linux:/usr/local/gsoap-2.7/gsoap/samples/calc # cat calc.h
/*




        The service operations and type definitions use familiar C/C++ syntax.

        The following methods are defined by this gSOAP service definition:

        add(a,b)
        sub(a,b)
        mul(a,b)
        div(a,b)
        pow(a,b)

        Compilation in C (see samples/calc):
        $ soapcpp2 -c calc.h
        $ cc -o calcclient calcclient.c stdsoap2.c soapC.c soapClient.c
        $ cc -o calcserver calcserver.c stdsoap2.c soapC.c soapServer.c

        Compilation in C++ (see samples/calc++):
        $ soapcpp2 -i calc.h
        $ cc -o calcclient++ calcclient.cpp stdsoap2.cpp soapC.cpp soapcalcProxy
.cpp
        $ cc -o calcserver++ calcserver.cpp stdsoap2.cpp soapC.cpp soapcalcServi
ce.cpp

        Note that soapcpp2 option -i generates proxy and service classes, which
        encapsulate the method operations in the class instead of defining them
        as global functions as in C.

        The //gsoap directives are used to bind XML namespaces and to define
        Web service properties:

        //gsoap <ns> service name: <WSDLserviceName> <documentationText>
        //gsoap <ns> service style: [rpc|document]
        //gsoap <ns> service encoding: [literal|encoded]
        //gsoap <ns> service namespace: <WSDLnamespaceURI>
        //gsoap <ns> service location: <WSDLserviceAddressLocationURI>

        Web service operation properties:

        //gsoap <ns> service method-style: <methodName> [rpc|document]
        //gsoap <ns> service method-encoding: <methodName> [literal|encoded]
        //gsoap <ns> service method-action: <methodName> <actionString>
        //gsoap <ns> service method-documentation: <methodName> <documentation>

        and type schema properties:

        //gsoap <ns> schema namespace: <schemaNamespaceURI>
        //gsoap <ns> schema elementForm: [qualified|unqualified]
        //gsoap <ns> schema attributeForm: [qualified|unqualified]
        //gsoap <ns> schema documentation: <documentationText>
        //gsoap <ns> schema type-documentation: <typeName> <documentationText>

        where <ns> is an XML namespace prefix, which is used in C/C++ operation
        names, e.g. ns__add(), and type names, e.g. xsd__int.

        See the documentation for the full list of //gsoap directives.

--------------------------------------------------------------------------------
gSOAP XML Web services tools
Copyright (C) 2001-2008, Robert van Engelen, Genivia, Inc. All Rights Reserved.
This software is released under one of the following two licenses:
GPL or Genivia's license for commercial use.
--------------------------------------------------------------------------------
GPL license.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA

Author contact information:
engelen@genivia.com / engelen@acm.org
--------------------------------------------------------------------------------
A commercial use license is available from Genivia, Inc., contact@genivia.com
--------------------------------------------------------------------------------
*/

//gsoap ns service name:        calc Simple calculator service
//gsoap ns service style:       rpc
//gsoap ns service encoding:    encoded
//gsoap ns service namespace:   http://127.0.0.1:8900/calc.wsdl
//gsoap ns service location:    http://127.0.0.1:8900/

//gsoap ns schema namespace:    urn:calc

//gsoap ns service method-documentation: add Sums two values
int ns__add(double a, double b, double *result);

//gsoap ns service method-documentation: sub Subtracts two values
int ns__sub(double a, double b, double *result);

//gsoap ns service method-documentation: mul Multiplies two values
int ns__mul(double a, double b, double *result);

//gsoap ns service method-documentation: div Divides two values
int ns__div(double a, double b, double *result);

//gsoap ns service method-documentation: pow Raises a to b
int ns__pow(double a, double b, double *result);

我现在修改成在本机调试了,请你再帮我看看,谢谢!

论坛徽章:
0
7 [报告]
发表于 2010-06-23 18:20 |只看该作者
本帖最后由 blue_sky 于 2011-07-07 10:05 编辑

rain_fish ,你能加我的QQ吗? 谢谢!

论坛徽章:
0
8 [报告]
发表于 2010-06-24 08:35 |只看该作者
非常感谢rain_fish 的热心解答,可是我用了你的方法,问题依旧,估计是我程序安装或系统环境有问题,我在编 ...
blue_sky 发表于 2010-06-23 18:15



    gsoap自带例子只需编译即可使用,不用重新生成那些文件啊。。。

论坛徽章:
0
9 [报告]
发表于 2010-06-24 08:38 |只看该作者
gsoap自带例子只需编译即可使用,不用重新生成那些文件啊。。。
rain_fish 发表于 2010-06-24 08:35



    连calc.h也不需要修改吗?

论坛徽章:
0
10 [报告]
发表于 2010-06-24 08:39 |只看该作者
linux系统需要安装其它什么软件吗?例如apach等。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP