1

I am using the HttpClient library to create a WCF Web API.

Snippet from service contract:

   [ServiceContract]
    public interface IMyService
    {      
        [WebGet(UriTemplate = "Foo/{id}/{securityKey}/{filename}")]
        HttpResponseMessage Foo(int id, string securityKey);
    }

When I hit the .svc in a browser I am getting this:

System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior contract: http://tempuri.org/:IMyService ----> System.Runtime.Serialization.InvalidDataContractException: Type 'System.Net.Http.HttpMethod' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.

Does this make sense to anyone? The same code worked in a different project, all the libraries are the same in this case, there must be some nuance I am missing.

Dan
  • 29,100
  • 43
  • 148
  • 207
  • Why would you try and do that? HttpResponseMessage is intended to be an abstraction of an HTTP response. Not something to be serialized over the wire. – Darrel Miller Apr 26 '13 at 14:38
  • Are you trying to use WCF REST instead of Web API because you prefer the routing? Try looking at the AttributeRouting extension for WebAPI. – Darrel Miller Apr 26 '13 at 14:41
  • You are not by chance using the old WCF REST Starter kit are you? http://aspnet.codeplex.com/wikipage?title=WCF%20REST It was the predecessor to what now is Web API and is no longer supported. Are you trying to create a REST based WCF service using the `webHttpBinding` binding or ASP.NET Web API project? – atconway Apr 26 '13 at 14:47
  • @DarrelMiller `HttpResponseMessage` is being used as the api is serving up images http://stackoverflow.com/questions/11125535/microsoft-web-api-return-a-file-use-byte. WCF api being used as this is a legacy service that pre-dated Web Api – Dan Apr 26 '13 at 15:58
  • Me too facing the same issue....any workaround? – Anil Purswani Jul 02 '13 at 10:35

1 Answers1

1

Change your WCF operation signature to return a Stream. Then make sure you set the Content-type header. That will allow you to return images from a WCF Rest endpoint.

Darrel Miller
  • 139,164
  • 32
  • 194
  • 243