0

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>
Senkwe
  • 2,256
  • 3
  • 24
  • 33
  • And how did you configure your service? WCF Service Application creates SOAP service not REST service so you must reconfigure it to be a REST service. – Ladislav Mrnka May 09 '11 at 11:32
  • Thanks Ladislav, how do I do that? I've so far set my config to use an endpoint that uses webHttp – Senkwe May 09 '11 at 11:36
  • Add your configuration to your question. – Ladislav Mrnka May 09 '11 at 11:37
  • 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. – Senkwe May 09 '11 at 12:46
  • You are using the WebHttpBinding, which is the old WCF REST stuff. You are not using the WebAPI stuff. I can tell you how to host it in a windows service, or in a ASP.NET environment, but I have not tried it just as a .svc file before. – Darrel Miller May 09 '11 at 13:10

2 Answers2

1

You are mixing up the new WCF Web API stuff with the old WCF REST stuff. Take a look at the HttpHelloResource sample as the simplest example of how to run a Web API service under IIS, or my blog post for an even simpler example of a service running in a console.

As for accepting a stream I think your simplest option would be an operation like this:

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

and you can get the stream by doing

var stream = request.Content.ContentReadStream
Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
  • Yes, I am actually using the new Web HTTP stuff. Both passing HttpRequestMessage and Stream are supported. Thanks :-) – Senkwe May 13 '11 at 10:32
  • Hovito: But the binding config you posted is for the old WCF REST! – Darrel Miller May 13 '11 at 11:04
  • Darrel, oh...what binding config should I have used instead? Oops, never mind. I see what you mean by your link to the sample. Thanks! – Senkwe May 16 '11 at 10:57
0

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

Senkwe
  • 2,256
  • 3
  • 24
  • 33