gsoap 开发:基于wsdl文件和C++语言开发客户端程序

    开发环境:ubuntu linux 386

1.下载gsoap-2.8.15

 2.解压缩到指定目录.(可以再安装gsoap到系统,但非必须)。

 3.获取wsdl文件。

这里假设我们要获取QQ 在线状态的 wsdl 文件.。在http://webservice.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl可以获取到.

建议大家把这个页面保存下来,而不要直接复制进虚拟机,因为编码的问题.另存为qqOnlineWebService.wsdl

4.把上面的wsdl文件存入我们的工作目录,并创建一个空的makefile 和myClient.cpp。如下图所示:

gsoap 开发:基于wsdl文件和C++语言开发客户端程序_第1张图片

5.编写makefile.内容如下:

server := myServer
client := myClient
                                                            
#your gsoap install directory
GSOAP_DIR=../../../gsoap-2.8

#web service name,added by danny
WSNAME0=soapqqOnlineWebServiceSoap
                                                            
#compiler
CORSS_COMPILER = 
G++ :=$(CORSS_COMPILER)g++
                                                            
#flags
LIBS:=  -lpthread -lm
INCLS := -I ./
CFLAGS := -g -O2 -Wall -Wno-deprecated-declarations
                                                            
#files
WSDL_FILES := qqOnlineWebService.h
GSOAP_FILES :=$(WSNAME0)Proxy.cpp $(WSNAME0)Proxy.h $(WSNAME0)Service.h $(WSNAME0)Service.cpp soapC.cpp soapH.h soapStub.h
CP_FILES := stdsoap2.h stdsoap2.cpp
COM_SOURCES := soapC.cpp  stdsoap2.cpp
COM_OBJS := $(COM_SOURCES:.cpp=.o)
SERVER_SOURCES := $(server).cpp $(WSNAME0)Service.cpp
SERVER_OBJS := $(SERVER_SOURCES:.cpp=.o)
CLIENT_SOURCES := $(client).cpp $(WSNAME0)Proxy.cpp
CLIENT_OBJS := $(CLIENT_SOURCES:.cpp=.o)
                                                            
TYPEMAP = $(wildcard *typemap.dat)
ifeq ( , $(TYPEMAP))
TYPEMAP = $(GSOAP_DIR)/gsoap/typemap.dat
endif
#MAKE
.PHONY: all   
all: wsdl gsoap cp $(client) #$(server)
                                                            
$(server):$(SERVER_OBJS) $(COM_OBJS)
	$(G++) $(INCLS) $(CFLAGS) -o $@ $^ $(LIBS)
$(client):$(CLIENT_OBJS) $(COM_OBJS)
	$(G++) $(INCLS) $(CFLAGS) -o $@ $^ $(LIBS)
$(COM_OBJS) $(CLIENT_OBJS) $(SERVER_OBJS):%.o:%.cpp
	$(G++) $(INCLS) $(CFLAGS) -o $@ -c $^  
                                                            
wsdl:
ifneq ($(WSDL_FILES), $(wildcard $(WSDL_FILES)))
	$(GSOAP_DIR)/gsoap/bin/linux386/wsdl2h -o $(TYPEMAP) $(wildcard *.wsdl) -o $(WSDL_FILES)
endif
gsoap:
ifneq ($(GSOAP_FILES), $(wildcard $(GSOAP_FILES)))
	$(GSOAP_DIR)/gsoap/bin/linux386/soapcpp2 -i  $(WSDL_FILES) -I $(GSOAP_DIR)/gsoap/import
endif
cp:
ifneq ($(CP_FILES), $(wildcard $(CP_FILES)))
	@cp $(GSOAP_DIR)/gsoap/stdsoap2.cpp $(GSOAP_DIR)/gsoap/stdsoap2.h ./ -v
endif
                                                            
#clean
clean:
	@rm -rfv *.o *~ *Proxy.h *.xml *.nsmap *.a *Object.h soapC.* $(WSNAME0)Service.* $(WSNAME0)Proxy.* $(server) $(client) *.nsmap $(CP_FILES)  $(GSOAP_FILES) $(WSDL_FILES)


 

6.编写myClient.cpp
#include "soapqqOnlineWebServiceSoapProxy.h" 
#include "qqOnlineWebServiceSoap.nsmap"     
int main() 
{     
    qqOnlineWebServiceSoapProxy service;     
    _ns1__qqCheckOnline request;     
    _ns1__qqCheckOnlineResponse response;           
    std::string num("1028667350");       
    request.qqCode = #     
    if( service.qqCheckOnline( &request, &response) == SOAP_OK)
   {         
        printf("QQ: %s state is %s\n",request.qqCode->data(), response.qqCheckOnlineResult->data()); 
    
   }
   else
   {             
        printf("Error\n");     
    }       
    service.destroy();     
    return 0; 
}


7.make

gsoap 开发:基于wsdl文件和C++语言开发客户端程序_第2张图片

8.运行可执行程序:

 

你可能感兴趣的:(gsoap 开发:基于wsdl文件和C++语言开发客户端程序)