Simple WCF (POX) service without complex serialization

I am a complete newcomer to WCF. I am trying to create a deployment of a very, very simple IIS 7.0 web service. For reasons beyond my control, it should be WCF, not ASMX. This is a service wrapper for an existing web application that simply does the following:

1) Receive a POST request with elements of an XML-encapsulated request form. Something like valuevalue. This untyped XML and XML is atomic (form), not a list of records / objects.

2) Add a couple of tags to the request XML and call another HTTP-based service with a simple POST + bare XML - this will actually be added by some internal SQL operations, but this is not a problem.

3) Receive an XML response from a third-party service and pass it as a response to the original caller in step 1.

Clients (step 1) will be a kind of web scripts, but can be any .aspx, python, php, etc.

I can't have SOAP, and the usual WCF-based REST examples with their contracts and serialization confuse me. This seems to be a very common and very simple problem conceptually. This would be easy to implement in code, but WCF is required for WCF.

Any pointers?

+4
source share
5 answers

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> <!-- Behavior config here --> </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); 
+4
source

I would look at the WCF REST Starter Kit @ http://www.asp.net/downloads/starter-kits/wcf-rest/ and PluralSite HowTo @ http://www.pluralsight-training.net/microsoft/olt/howtovideo .aspx? a = aaron-skonnard & n = http-plain-xml-services . Those who should start you and guide you in the right direction.

+1
source

I think the video you are talking about is available from here

+1
source

Ben has the right video - unfortunately, this video is for "Subscribers Only" on the Pluralsight website :-( :-(: - (

Fortunately, almost all of these intro videos are also available from the MSDN WCF REST Developer Center - with the exception of the one Ben was talking about.

But the WCF REST developer must still have a lot of good input material to quickly and quickly speed up work with WCF REST! A.

0
source

In NET 4.0, here

0
source

Source: https://habr.com/ru/post/1308815/


All Articles