gsoap 天气预报

  1. mkdir weather
  2. 拷贝gsoap-2.8/gsoap/stdsoap2.c stdsoap2.h 和typemap.dat 到 weather 目录。
  3. wsdl2h -c -o weather.h http://www.webservicex.net/globalweather.asmx?WSDL
  4. soapcpp2 -CL weather.h -I../gsoap-2.8/gsoap/import
  5. vim main_client.c

    
    #include "GlobalWeatherSoap.nsmap"
    
    
    #include "soapH.h"
    
    int main(int argc, char * argv[])
    {
        struct soap * soap = soap_new();
        struct _ns1__GetWeather getweather;
        struct _ns1__GetWeatherResponse getweather_response;
        //char * city = "BeiJing";
        //char * country = "China";
    
        if(argc != 3){
            printf("argc is not 3\n");
            goto OUT;       
        }
        printf("city: %s\n", argv[1]);
        printf("country: %s\n", argv[2]);
        getweather.CityName = argv[1];
        getweather.CountryName = argv[2];
        if( soap_call___ns1__GetWeather(soap, NULL, NULL, &getweather, &getweather_response) == SOAP_OK)
            printf("GetWeatherResponse: \r\n%s\r\n", getweather_response.GetWeatherResult);
        else
            soap_print_fault(soap, stderr);
    OUT:
        soap_destroy(soap);
        soap_end(soap);
        soap_free(soap);
        return 0;
    }
  6. gcc -o weather_client main_client.c soapC.c soapClient.c stdsoap2.c
  7. 编译生产weather_client
  8. ./weather_client beijing china

    city: beijing
    country: china
    GetWeatherResponse: 
    <?xml version="1.0" encoding="utf-16"?>
    <CurrentWeather>
        <Location>Beijing, China (ZBAA) 39-56N 116-17E 55M</Location>
        <Time>Aug 03, 2016 - 10:30 PM EDT / 2016.08.04 0230 UTC</Time>
        <Wind> from the ESE (110 degrees) at 4 MPH (4 KT) (direction variable):0</Wind>
        <Visibility> 2 mile(s):0</Visibility>
        <Temperature> 89 F (32 C)</Temperature>
        <DewPoint> 77 F (25 C)</DewPoint>
        <RelativeHumidity> 66%</RelativeHumidity>
        <Pressure> 29.83 in. Hg (1010 hPa)</Pressure>
        <Status>Success</Status>
    </CurrentWeather>
  9. 也可编写makefile文件
    参考 http://blog.chinaunix.net/uid-21768364-id-4648583.html

    my_server:=calc_server
    my_client:=weather_client
    my_test:=getcity
    
    # your gsoap install directory
    #GSOAP_DIR = /root/Desktop/gsoap-2.8
    GSOAP_DIR = 
    
    # compiler
    CORSS_COMPILER = 
    
    CC=$(CORSS_COMPILER)gcc
    
    # flags
    LIBS:=-lpthread -lm
    INCLS:=-I./ 
    CFLAGS:=-O2 -Wall
    
    COM_SOURCES=soapC.c stdsoap2.c
    COM_OBJS=$(COM_SOURCES:.c=.o)
    SER_SOURCES=main_server.c soapServer.c
    CLI_SOURCES=main_client.c soapClient.c
    TEST_SOURCES=getcity_client.c soapClient.c
    SER_OBJS=$(COM_OBJS) $(SER_SOURCES:.c=.o)
    CLI_OBJS=$(COM_OBJS) $(CLI_SOURCES:.c=.o)
    TEST_OBJS=$(COM_OBJS) $(TEST_SOURCES:.c=.o)
    
    
    all: wsdl gsoap makeClient makeTest
    
    WSDL_FILES := temp.h
    GSOAP_FILES := soapClient.c soapServer.c soapC.c soapH.h soapStub.h
    WSDL_SOURCE := $(wildcard *.wsdl)
    
    wsdl:
    ifeq ($(strip $(WSDL_SOURCE)),)
        @echo not find *.wsdl file.
    else
    ifneq ($(WSDL_FILES), $(wildcard $(WSDL_FILES)))
        wsdl2h -c -o $(WSDL_FILES) $(WSDL_SOURCE)
    endif
    endif
    
    gsoap:
    ifneq ($(GSOAP_FILES), $(wildcard $(GSOAP_FILES)))
        soapcpp2 -CL $(WSDL_FILES) -I../gsoap-2.8/gsoap/import
    endif
    
    makeClient:$(CLI_OBJS)
        $(CC) $(INCLS) $(CFLAGS) -o $(my_client) $^ $(LIBS)
    
    makeServer:$(SER_OBJS)
        $(CC) $(INCLS) $(CFLAGS) -o $(my_server) $^ $(LIBS)
    
    makeTest:$(TEST_OBJS)
        $(CC) $(INCLS) $(CFLAGS) -o $(my_test) $^ $(LIBS)
    
    $(CLI_OBJS):%.o:%.c
        $(CC) $(INCLS) $(CFLAGS) -o $@ -c $^
    $(TEST_OBJS):%.o:%.c
        $(CC) $(INCLS) $(CFLAGS) -o $@ -c $^
    
    clean:
        @rm -rfv *.o *~ *Proxy.h *Object.h $(my_server) $(my_client) $(my_test)
    
    deepclean:
        @rm -rfv *.o *~ *Proxy.h *Object.h $(my_server) $(my_client) $(my_test) *.xml *.nsmap $(GSOAP_FILES) $(WSDL_FILES) 
    
  10. make clean // 清除
    make deepclean // 清除所有,包括wsdl2h和soapcpp2产生的文件
    make // 编译,生成可执行程序 weather_client 和 getcity

  11. vim getcity_client.c

#include "GlobalWeatherSoap.nsmap"
#include "soapH.h"
int main(int argc, char * argv[])
{
    struct soap * soap = soap_new();
    struct _ns1__GetCitiesByCountry getcity;
    struct _ns1__GetCitiesByCountryResponse getcity_response;

    if(argc != 2){
        printf("argc is not 2\n");
        goto OUT;       
    }
    printf("country: %s\n", argv[1]);
    getcity.CountryName = argv[1];
    if( soap_call___ns1__GetCitiesByCountry(soap, NULL, NULL, &getcity, &getcity_response) == SOAP_OK)
        printf("GetCityResponse: \r\n%s\r\n", getcity_response.GetCitiesByCountryResult);
    else
        soap_print_fault(soap, stderr);
OUT:
    soap_destroy(soap);
    soap_end(soap);
    soap_free(soap);
    return 0;
}`
./getcity china
country: china
GetCityResponse: 
<NewDataSet>
  <Table>
    <Country>China</Country>
    <City>Beijing</City>
  </Table>
  <Table>
    <Country>China</Country>
    <City>Hohhot</City>
  </Table>
  ...
  <Table>
    <Country>China</Country>
    <City>Qiqihar</City>
  </Table>
  <Table>
    <Country>China</Country>
    <City>Dalian</City>
  </Table>
</NewDataSet>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值