Click here to Skip to main content
12,884,509 members (31,561 online)
Click here to Skip to main content
Add your own
alternative version


1 bookmarked
Posted 2 Aug 2013

WCF channelfactory and DataContracts (complex data types) to consume gSoap web services

, 2 Aug 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Datacontract channelfactory WCF way of consuming SOAP web services written in C, C++ using gSoap framework on Linux platform


In this article, I am explaining the data contract and channelfactory WCF way of consuming a web service written in C/C++ using gSoap framework on Linux platform. Here service is implemented on Linux (C++ SOAP Server) platform using gSoap and client is WCF(C#-WCF SOAP Agent) based on Windows platform. We are exchanging user defined data type as the inter-operability issues are generally faced while exchanging them. Data contract abstractly describes the data to be exchanged between a service and a client thereby making it easy to inter-operate different technologies.     

Solving interoperability issues is one of the critical aspects of web services programming. This article shows how to make WCF (Windows Communication Foundation) and gSOAP interoperable. In WCF there are several ways of consuming web services like ServiceReference, MessageContracts/DataContracts using channelfactory etc. gSoap framework is used to implement and consume web services in C, C++ on various platforms.    

While I was working on a PoC for making WCF-gSoap interoperable. I went through a lot of searches and queries over google and other search engines. There I saw that many people are trying to make it interoperable and I could not find a solution over net. I think it can be a starting point for those who are trying to communicate WCF and gSoap.

Here onwards we are going to discuss the working WCF-gSoap Sample calc example attached with this article. In this example there is WCF client which sends SOAP request to perform calculations on integer data. gSoap Server (here listening at port 8080) serves the request and sends SOAP response back with complex data type data contract (class Result type defined below). To make gSOAP response
understandable by DataContractSerializer, You have to make certain changes on WCF client. Changes on WCF client and gSoap server both are required as follows:

Changes on WCF client side (SOAP Agent): 

The default namespace used by dataContract is a URI which is constructed based on the namespace the datacontract is defined in. But it is difficult to set such namespace on gSoap side as it is very much specific to Windows & WCF. Hence to deserialize  the response from the gSoap server, we set datacontract namespace to blank as follows:

[DataContract(Namespace = "")                                      
public class Result
    public int resAdd { get; set; }
    public int resSub { get; set; }
    public int resMul { get; set; }
    public int resDiv { get; set; }

Changes On gSOAP Service (SOAP Server): 

  1. The default namespace used by the WCF is “”. Hence instead of modifying the service contract namespace on WCF Interface, we make following change in gSoap directives settings. It makes all methods on the gSOAP server coming under this web service lie under common WCF compliant namespace. The change is: 
  2. //gsoap ns service namespace:
  3. Also you need to change the service style to document as follows. By default it is rpc/encoded after your changes it becomes document/encoded. 
  4. //gsoap ns service style:    document
  5. You have to modify the function parameter name of web methods to webmethodnameResult. For example if the method name is Add, then the return parameter name should be AddResult. Look at the following declaration:
  6. int ns__PerformCalculations(int a, int b, struct Result &PerformCalculationsResult);

The equivalent representation of data contract on the gSoap server side is as follows:

struct Result
    //Date members are arranged in sorted order as compared to WCF datacontract
    //because according to my observation data contract deserializer uses this technique.
    int resAdd;
    int resDiv;
    int resMul;
    int resSub;

Thus after making the changes on the WCF and gSoap side, compile the client and server. WCF service gets compiled using visual studio and compile gSoap service using ReadMe.txt provided with the attached zip file. After compilation run the server binary which will start listening at the port you specify and then run the WCF client console application. You may use HTTP debugger to see the traffic flowing back and forth. Thus you can make your WCF client talk to gSoap service.  I have attached working client and service with this article which can help you to understand the things practically and in detail.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Prasad Agarmore
Software Developer
India India
I hold a bachelors degree in Computer Engineering. I have worked on different technologies like WCF, C#, C++, Java, SOAP, shell scripting, python etc. I am mainly good at WCF, Linux/C++ and SOAP web services. I have solved many SOAP inter-operability issues. I have experience of developing basic Android and iPhone apps. I like to learn new technologies.

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170422.1 | Last Updated 2 Aug 2013
Article Copyright 2013 by Prasad Agarmore
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid