开发者

WCF RequestFormat for WebGet and WebInvoke

开发者 https://www.devze.com 2023-01-08 23:51 出处:网络
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

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">
  <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/"> 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号