I have a client requirement where I need to expose a web service which takes XML. Client will consume my web service and send XML .

This web service need to be async.

Could you please suggest any good proven approach ? with advantage / disadvantage

2 Answers 2


Are you sure the actual payload is XML, or just that the serialization format is XML?

Usually when people use WCF Services they define an object (in C#, for example) to pass across the wire. A good style is to pass a single C# object as the parameter to your service (FooRequest) and have the service return a single object (FooResponse). These objects will contain all the data you need to move. Of course, they can reference other objects, etc. You don't want to pass over any data structures that are .NET-specific (like a Dictionary object or a DataSet); ideally you will pass generic objects that make sense in any platform.

You will need to ensure your objects are serializable, but that is usually not hard.

It just so happens that WCF chooses to serialize this to XML while it travels across the wire, but you don't need to do that work explicitly. You don't necessarily even need to know this. There are other possible formats too, like JSON.

Just go through virtually any WCF tutorial (such as this one) to see what I mean. Focus on clean interfaces, clear logic, good names - not on the wire format. You may want to read about SOA principles.

[edit] Regarding ASync - if you import the WSDL with Visual Studio, a client-side proxy will be generated. This is how you access the service from client code. This will include methods that allow you to call the service asynchronously. See the tuturial link mentioned earlier.

Even if on the off chance your requirement is to include some arbitrary XML, you can still use this approach. Simply place the XML as a string into a string member in your request/response objects.

Good luck! -Bill


You'll have to use a XMLDocument Object as a parameter to your Operation Contract. Nothing else need to be done special.

You can take any standard example for writing a service. Use XMLDocument class as a Operation contract parameter. This service can be consumed asynchronously using standard methods. You can refer to How to: Call WCF Service Operations Asynchronously

  • Actually, the operation implementation method needs to be marked like the code shown below. Without the XmlSerializerFormat you'll get serialzation errors. [OperationContract, XmlSerializerFormat]
    – Sixto Saez
    Jul 25, 2011 at 19:19
  • But will this work if this is consumed by not microsoft platoform?
    – vinsha
    Jul 28, 2011 at 10:30
  • 1
    No matter which object/class you use in your service, wsdl is going to produce an xml based document. It can be consumed by any platform which is capable of parsing the WSDL and producing its own language specifics. You may have to chose the basicHTTP binding for interoperability, with some security compatible with the consuming platform. Jul 28, 2011 at 14:38
  • 1
    @Saravanan I agree with your comment, not your post. No need to use a XMLDocument as a parameter, because whatever type if used will be serialized to XML anyway. Aug 25, 2011 at 1:53
  • If it is a regular object, yes, you are correct. From the question, my assumption was that the client might send a raw XML. That's the reason I suggested XMLDocument. Aug 25, 2011 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.