WCF service which takes XML file

wcfweb services

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

Best Answer

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

Related Topic