Creating a POX service is usually as simple as adding a few attributes and changing a few parameters in web.config .
First add [WebInvoke] to the POX methods of the service contract:
[ServiceContract] public interface IMyService { [OperationContract] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare)] MyResult MyOperation(MyClass c); }
Sometimes you also need to specify an XML namespace for your data contracts:
[DataContract(Namespace = "http://example.com/myclass")] public class MyClass { ... }
Then configure your web.config to use webHttpBinding and the behavior of webHttp :
<system.serviceModel> <services> <service behaviorConfiguration="MyApp.MyBehavior" name="MyApp.MyService"> <endpoint address="" binding="webHttpBinding" contract="MyApp.IMyService" behaviorConfiguration="POX" bindingNamespace="http://example.com/"> <--! More endpoint configuration here --> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <serviceBehaviors> </serviceBehaviors> <endpointBehaviors> <behavior name="POX"> <webHttp/> </behavior> </endpointBehaviors> </behaviors> </system.serviceModel>
What about that. It seems harder than it really is.
Note. If you really want to get untyped XML instead of a serialized class, change your method to get XElement , as in:
[WebInvoke(...)] MyResult MyOperation(XElement element);
source share