18,356
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include "soapSmsWBSService.h"
#include "SmsWBS.nsmap"
int http_get(struct soap * soap);
int main(int argc, char **argv)
{
SmsWBSService sms;
if (argc < 2)
sms.serve(); /* serve as CGI application */
else
{
int port = atoi(argv[1]);
if (!port)
{
fprintf(stderr, "Usage: SmsWBSserver++ <port>\n");
exit(0);
}
/* run iterative server on port until fatal error */
sms.fget = http_get;
sms.bind("192.168.2.136", 80, 0);
if (sms.run(80))
{
sms.soap_stream_fault(std::cerr);
exit(-1);
}
}
return 0;
}
int SmsWBSService::add(int num1, int num2, int *sum)
{
*sum = num1 + num2;
return SOAP_OK;
}
//能够远程读取wsdl文件
int http_get(struct soap * soap)
{
FILE *fd = NULL;
char *s = strchr(soap->path, '?');
if (!s || strcmp(s, "?wsdl"))
return SOAP_GET_METHOD;
fd = fopen("SmsWBS.wsdl", "rb");
if (!fd)
return 404;
soap->http_content = "text/xml";
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;
}
fclose(fd);
soap_end_send(soap);
return SOAP_OK;
}