gsoap 写的WebServer服务端不能在IE上正确显示wsdl信息(各位大哥帮帮忙,我只有那么点分哦)
语言:C/C++, gsoap_linux_2.7.9j(最新)
功能:客户端通过调用服务端的接口,能够把一段比特流传送到服务端
问题:服务端写好后,通过我服务器ip在IE上不能正确得到wsdl信息;
在IE上键入(程序运行的服务器实际ip) http://192.168.18.180:9090/
显示如下:
<?xml version= "1.0 " encoding= "UTF-8 " ?>
- <SOAP-ENV:Envelope xmlns:SOAP-ENV= "http://schemas.xmlsoap.org/soap/envelope/ " xmlns:SOAP-ENC= "http://schemas.xmlsoap.org/soap/encoding/ " xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance " xmlns:xsd= "http://www.w3.org/2001/XMLSchema " xmlns:ns= "urn:OCWeb ">
- <SOAP-ENV:Body>
- <SOAP-ENV:Fault SOAP-ENV:encodingStyle= "http://schemas.xmlsoap.org/soap/encoding/ ">
<faultcode> SOAP-ENV:Client </faultcode>
<faultstring> HTTP GET method not implemented </faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
小弟实在不懂为什么会在Body部分出错,望指点,谢谢!代码如下:
OCWeb.h部分:
//gsoap ns service name:OCWeb
//gsoap ns service style:rpc
//gsoap ns service encoding:encoded
//gsoap ns service namespace:http://192.168.18.180:9090/OCWeb.wsdl
//gsoap ns service location:http://192.168.18.180:9090
//gsoap ns schema namespace:urn:OCWeb
struct xsd__base64Binary{
unsigned char *__ptr;
int __size;
};
int ns__transferStream(struct xsd__base64Binary *pstBinary, double *result);
OCWebServer.c部分的代码:
#include "soapH.h "
#include "OCWeb.nsmap "
unsigned char* data = NULL;
int iNum = 0;
int main(int argc, char **argv)
{
int 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 (m < 0){
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 (s < 0){
soap_print_fault(&soap, stderr);
exit(-1);
}
soap_serve(&soap);
soap_end(&soap);
}
}
return 0;
}
int ns__transferStream(struct soap *soap, struct xsd__base64Binary *pstBinary, double *result)
{
*result = pstBinary-> __size;
iNum = pstBinary-> __size;
data = new unsigned char[pstBinary-> __size + 1];
memcpy(data, pstBinary-> __ptr, pstBinary-> __size);
//把从客户端传来的数据输出
fprintf(stdout, "\n ");
for(int j = 0; j < iNum; j++) {
fprintf(stdout, "%04x ", data[j]);
}
fprintf(stdout, "\n ");
//输出完就释放
if(data) {
delete []data;
}
return SOAP_OK;
}
makefile如下:(gsoap安装目录:/usr/local/gsoap-linux-2.7)
SOAPCPP2=/usr/local/gsoap-linux-2.7/bin/soapcpp2
SOAP2H=/usr/local/gsoap-linux-2.7/stdsoap2.h
SOAP2C=/usr/local/gsoap-linux-2.7/stdsoap2.c
STDSOAP2=/usr/local/gsoap-linux-2.7/stdsoap2.cpp
CC=gcc
CPP=g++
LIBS=
COFLAGS=-O2
CWFLAGS=-Wall
CIFLAGS=-I../..
CMFLAGS=
CFLAGS= $(CWFLAGS) $(COFLAGS) $(CIFLAGS) $(CMFLAGS)
all:server
server:OCWeb.h OCWebServer.c $(SOAP2H) $(SOAP2C)
$(SOAPCPP2) -c OCWeb.h
$(CPP) $(CFLAGS) -o server OCWebServer.c soapC.c soapServer.c $(SOAP2C) -lm $(LIBS)
运行$./server 9090
程序和gsoap自带例子calc差不多,请大哥们帮帮忙,谢谢!
[解决办法]
mark,等高人讲解.
[解决办法]
应该没错,你写个客户端调用下试试!你用浏览器访问的,没有给服务端传参数调用其方法ns_transferStream,所以就显示 HTTP GET method not implemented! 冒昧的问下,你是不是参加了齐鲁软件设计大赛?
[解决办法]
同样问题,帮顶!
[解决办法]
用gSOAP写的客户端和服务器端,客户端发送的是HTTP POST请求,而你用浏览器发送给服务器的请求是HTTP GET请求。你可以参考gSOAP的用户文档看看如何在服务器端实现HTTP GET的支持
[解决办法]
根据gSOAP文档所说,你需要设置soap.fget回调函数。例如:
你在你的main函数中的soap_init(&soap);的下面加入:
soap.fget = http_get;
然后写一个函数int http_get(strcut soap *soap)
{
soap_response(soap, SOAP_HTML);
soap_send(soap, " <HTML> My Web sevice is operational </HTML> ");
soap_end_send(soap);
return SOAP_OK;
}
当然了别忘了在main函数前面声明一下此函数:int http_get(strcut soap *soap);
运行/server 9090
在浏览器中输入http://你的主机地址:9090
应该在浏览器上显示:My Web sevice is operational