+ -
当前位置:首页 → 问答吧 → gsoap自带的例子,服务端出现“段错误”是什么原因啊?在线等!!!

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

时间:2010-06-21

来源:互联网

是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:
[email protected] / [email protected]
--------------------------------------------------------------------------------
A commercial use license is available from Genivia, Inc., [email protected]
--------------------------------------------------------------------------------
*/

#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:
[email protected] / [email protected]
--------------------------------------------------------------------------------
A commercial use license is available from Genivia, Inc., [email protected]
--------------------------------------------------------------------------------
*/

#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函数中出现的,请教高手是哪里出问题了,谢谢!

作者: blue_sky   发布时间: 2010-06-21

哥们儿回去帮你查查。。。如果朝鲜赢的话。。。

作者: rain_fish   发布时间: 2010-06-21

回复 blue_sky


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

作者: rain_fish   发布时间: 2010-06-21

错误原因可能是:

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

成功!

作者: rain_fish   发布时间: 2010-06-21

哥们儿你也没有在线等啊。。。。

作者: rain_fish   发布时间: 2010-06-21