wcfrestwcf-http

Using WCF Web apis (REST) to support Streamed data


I have the following problem. Let me describe the steps I took so far...

  1. I created a new WCF Service Application in Visual Studio
  2. I then updated the project via Nuget to get the latest web http libs (webapi.dll)
  3. I then created a service method that looks like this

`

[ServiceContract]
public interface IService
{
        [OperationContract]
        [WebInvoke(Method="POST", UriTemplate="{value}")]
        string GetData(int value, Stream inputDocument);
}

`

Now attempting to view the my .svc in the browswer results in an error that says "For request in operation GetData to be a stream the operation must have a single parameter whose type is Stream"

I know this is an issue with configuration, I just don't know what needs to change in web.config Mind you, this seems to have been a common problem in WCF before the new HTTP support, I'm somewhat surprised that this doesn't work out of the box with the new APIs.

Any pointers?

Thanks

[EDIT] I've included my config...

<system.serviceModel>
    <services>
      <service name="MyService.Service" behaviorConfiguration="serviceBehaviour">
        <endpoint behaviorConfiguration="endPointBehaviour" address="" binding="webHttpBinding" contract="MyService.IService"/>
      </service>
    </services>    
    <bindings>
      <webHttpBinding>
        <binding transferMode="Streamed" name="webHttpBinding" />
      </webHttpBinding>
    </bindings>

    <behaviors>
      <endpointBehaviors>
        <behavior name="endPointBehaviour">
          <webHttp/>
        </behavior>
      </endpointBehaviors>

      <serviceBehaviors>
        <behavior name="serviceBehaviour">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>    
  </system.serviceModel>

Solution

  • Ok, so it seems the error message was taking me down the wrong path. I think that error message needs to be far more descriptive. Basically there's nothing wrong my code at all, it just doesn't make sense to point my browser to the .svc file as the service is not quite a WCF service. I learmt this by going ahead and accessing the service via code. And it works. Thanks for the help