3,055
社区成员
![](https://csdnimg.cn/release/cmsfe/public/img/topic.427195d5.png)
![](https://csdnimg.cn/release/cmsfe/public/img/me.40a70ab0.png)
![](https://csdnimg.cn/release/cmsfe/public/img/task.87b52881.png)
![](https://csdnimg.cn/release/cmsfe/public/img/share-circle.3e0b7822.png)
#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;
if (sms.run(port))
{
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;
}