GSOAP calc 示例

  1. mkdir calc
  2. 拷贝gsoap-2.8/gsoap/stdsoap2.c stdsoap2.h 和typemap.dat 到 weather 目录。
  3. wsdl2h -c -o calc.h http://www.genivia.com/calc.wsdl
  4. soapcpp2 -CL calc.h
  5. vim main_client.c

    #include "calc.nsmap"
    #include "soapH.h"
    
    int main()
    {
        struct soap * soap = soap_new();
        double sum;
        if( soap_call_ns2__add(soap, NULL, NULL, 1.23, 2.34, &sum) == SOAP_OK)
            printf("Sum=%g\n", sum);
        else
            soap_print_fault(soap, stderr);
        soap_destroy(soap);
        soap_end(soap);
        soap_free(soap);
        return 0;
    }
    
  6. gcc -o calc_client main_clinet.c soapC.c soapClient.c stdsoap2.c
  7. 编译生成calc_client
  8. ./calc_clinet
    Sum=3.57
  9. 也可编写makefile文件
    参考 http://blog.chinaunix.net/uid-21768364-id-4648583.html

    my_server:=calc_server
    my_client:=calc_client
    my_test:=calc_test
    
    # 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
    SER_OBJS=$(SER_SOURCES:.c=.o) $(COM_OBJS)
    CLI_OBJS=$(COM_OBJS) $(CLI_SOURCES:.c=.o)
    
    
    all: wsdl gsoap makeClient
    
    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 -L $(WSDL_FILES)
    endif
    
    makeClient:$(CLI_OBJS)
        $(CC) $(INCLS) $(CFLAGS) -o $(my_client) $^ $(LIBS)
    
    makeServer:$(SER_OBJS)
        $(CC) $(INCLS) $(CFLAGS) -o $(my_server) $^ $(LIBS)
    
    makeTest:
    
    $(CLI_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 // 编译,生成可执行程序 calc_client

你可能感兴趣的:(linux,gsoap)