views:

318

answers:

1

I have WCF services exposed using WebGet and WebInvoke that require the data to be wrapped in xml. I would prefer to be able to return raw data without it being wrapped in xml and also allow clients the ability to invoke my service without needing to wrap the request in xml.

I'm serializing the data using protocol buffers and converting the result to a base64String so a WebGet response looks like:

<BinVehicleResp xmlns="http://schemas.datacontract.org/2004/07/NTouchServices.Binary_Types" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
  <BinVehicle>CgsxMjMtNDU2LTc4ORIFNDQwMDAaBUJsYWNrIgVKZXR0YVIJCJrYqoXAShAE (BINARY DATA)</BinVehicle>
</BinVehicleResp>

And a WebInvoke input must look at a minimum like:

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"&gt; BINARY DATA </string>

I really just want the BINARY DATA part, especially for the WebInvoke. I can live with the WebGet how it is. Does anyone have any suggestions on how I can allow clients to be able to do an HTTP POST using WebInvoke without the need to wrap the request in xml? Thanks.

A: 

I'm not sure I understand the question completely. You state that you require the data being POSTed to be wrapped in XML, but then ask how you can have the data POSTED without wrapping it in XML. My initial answer would be to declare your WebInvoke service method using the BodyStyle parameter:

[OperationContract]
[WebInvoke(Uri="SomeMethod?x={foo}&y={bar}", BodyStyle=WebMessageBodyStyle.WrappedRequest)]
public string SomeMethod(string foo, string bar) {
...
}

Here's the MSDN documentation for BodyStyle -- you can set it to be Bare (neither response nor request are wrapped), Wrapped, or WrappedRequest/Response.

I hope this helps.

David Hoerster
This looks promising, I will try it out. Sorry the question got confusing. What I actually meant was in order for it to be successful with the way it is currently WCF requires the requests and responses to be wrapped - however, I personally would like for the responses not to be wrapped.
Sean
No problem. Let me know if that worked - I'm curious. Thanks!
David Hoerster