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.

5
  • 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. Commented Apr 26, 2013 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. Commented Apr 26, 2013 at 14:41
  • You are not by chance using the old WCF REST Starter kit are you? 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? Commented Apr 26, 2013 at 14:47
  • @DarrelMiller HttpResponseMessage is being used as the api is serving up images stackoverflow.com/questions/11125535/…. WCF api being used as this is a legacy service that pre-dated Web Api Commented Apr 26, 2013 at 15:58
  • Me too facing the same issue....any workaround? Commented Jul 2, 2013 at 10:35

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.