tags:

views:

258

answers:

3

I'm a complete WCF novice. I'm trying to build a deploy a very, very simple IIS 7.0 hosted web service. For reasons outside of my control it must be WCF and not ASMX. It's a wrapper service for a pre-existing web application that simply does the following:

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

2) Add a couple of tags to the request XML and the invoke another HTTP-based service with a simple POST + bare XML -- this will actually be added by some internal SQL ops but that isn't the issue.

3) Receive the XML response from the 3rd party service and relay it as the response to the original calling client in Step 1.

The clients (step 1) will be some sort of web-based scripting but could be anything .aspx, python, php, etc.

I can't have SOAP and the usual WCF-based REST examples with their contracts and serialization have me confused. This seems like a very common and very simple problem conceptually. It would be easy to implement in code but IIS-hosted WCF is a requirement.

Any pointers?

A: 

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

Ben.Vineyard
A: 

Ben has the right video - unfortunately, that video is "For Subscribers Only" on the Pluralsight site by now :-( :-( :-(

Luckily, almost all those intro videos are also available from the MSDN WCF REST Developer Center - except the one Ben mentioned ....

But the WCF REST developer center should still have plenty of good intro material to get up to speed with WCF REST easily and quickly!

marc_s
:( That was such a good video, but I agree the ones on MSDN are just as informative.
Ben.Vineyard
A: 

Building a POX service is usually as simple as adding a few attributes and changing a few settings in your 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 have to specify an XML namespace for your data contracts:

[DataContract(Namespace = "http://example.com/myclass")]
public class MyClass { ... }

Then set up your web.config to use webHttpBinding and the webHttp behaviour:

<system.serviceModel>
    <services>
        <service behaviorConfiguration="MyApp.MyBehavior" name="MyApp.MyService">
            <endpoint address="" binding="webHttpBinding"
                      contract="MyApp.IMyService" behaviorConfiguration="POX"
                      bindingNamespace="http://example.com/"&gt;
                <--! 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>

That's about it. It seems harder than it really is.

Note: If you actually want to receive untyped XML instead of a serialized class, then change your method to receive an XElement, as in:

[WebInvoke(...)]
MyResult MyOperation(XElement element);
Aaronaught
Aaron's answer seems interesting but I am a complete novice with WCF so I'm not sure where to begin; even at the simplest step: what kind of project to create; which assemblies to include; files to create, etc. It's pathetic. Am a I creating a web site and then adding .svc and .cs files? Am I using one of the WCF templates? I'm sorry to be such a dunce.
@jammer: Just use the "WCF Service Application" template and add the `System.ServiceModel.Web` assembly. You don't have to do much else other than make the changes shown here; it goes and creates a default service for you which you can rename/change.
Aaronaught