Click here to Skip to main content
15,392,636 members
Articles / Programming Languages / C#
Technical Blog
Posted 8 Jan 2012

Tagged as


2 bookmarked

WCF Web Service Call to Another WCF Web Service returns no data

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
8 Jan 2012CPOL2 min read
WCF Web Service Call to Another WCF Web Service returns no data

Problem Statement

I have a WCF IIS hosted web service which uses another WCF web service hosted in a different web application. The call to the other Web service always returns null or empty values on the data members of the data contract. If I call the other web service directly from a client application, the response of the service has no problem, and all the properties are populated correctly. I configured a trace on the request, and I can see that the second web service is handling the requests, but the data is not returned.


This problem is common when a WCF Web service acts as a client for another WCF Web service, and it can be addressed by adding a namespace to the Web service behavior and data contract that is used for the response. If you take a look at a trace file, you will be able to see that the actual data is coming back on XML nodes with a namespace that was created dynamically. Since the client does not understand this namespace, the data is placed on the ExtensionData field of the response (see inner Members collections). You can see this using the debugger. The actual data members are null or set to default values (defined in the class).

It is always recommended to set the service behavior and data contracts to a namespace to prevent unexpected behaviors. Take a look at the ServiceBehavior attribute on the service contract declaration and the DataContract attribute and assign a namespace as follows:

[ServiceBehavior(Namespace = " urn:MyserviceNameSpace")]    
public class MyService: IMyService 

public class MyResponse

Note how the Name attribute also matches the class name. After making these changes, the client proxy (for the service consuming the second web service) needs to be updated. This downloads the namespace declarations that would allow the binding to be accurate. If you debug this again, you will see that the ExtensionData Members collection is now null. This is because the binding is now correctly using the class properties.

I hope this helps.

This article was originally posted at


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


About the Author

Architect OG-BITechnologies
United States United States
Software engineer, author & speaker who enjoys mentoring, learning, speaking and sharing with others about software development technologies. Microsoft MVP.

My Blog

Comments and Discussions

-- There are no messages in this forum --