用gSOAP开发Web Service服务端,按照gsoap的User's Guide的sample,自己仿着写了个例子,但是在浏览器上输入: http://localhost:18083/访问的网页显示
XML code <? 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:tmsc ="urn:tmsc" > - < 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 >根据gSOAP文档所说,你需要设置soap.fget回调函数。例如: 你在你的main函数中的soap_init(&soap);的下面加入: soap.fget = http_get; 即:soap_init(&soap); soap.fget = http_get;m = soap_bind(&soap, NULL, 18083, 100);
int http_get(strcut soap * soap) { FILE * fd = NULL; fd = fopen( " ns.wsdl " , " rb " ); // open WSDL file to copy if ( ! fd) { return 404 ; // return HTTP not found error } soap -> http_content = " text/xml " ; // HTTP header with text /xml content soap_response(soap,SOAP_FILE); for (;;) { size_t r = fread(soap -> tmpbuf, 1 , sizeof (soap -> tmpbuf), fd); if ( ! r) { break ; } if (soap_send_raw(soap, soap -> tmpbuf, r)) { break ; // cannot send, but little we can do about that } } fclose(fd); soap_end_send(soap); return SOAP_OK; }编译后在浏览器中输入 http://localhost:18083/ 连接成功。
附:关于gsoap的使用心得可以参考这篇http://www.cppblog.com/qiujian5628/archive/2008/06/19/54019.html
转载于:https://www.cnblogs.com/Laokong-ServiceStation/archive/2011/04/29/2032331.html