Topics: Web Api
Jul 11, 2011 at 5:36 PM

I realize I have been missing something completely in using the Web API Preview 4.  You can see part of my problem here:

I basically have figured out that I have to build HttpRequestMessages and HttpResponseMessages manually set the formatters explicitly each and every time I need to call from a client app, ie: 

               XmlMediaTypeFormatter formatter = new XmlMediaTypeFormatter();
                formatter.SetSerializer<DiscoveryCodingCredentials>(new DataContractSerializer(typeof(DiscoveryCodingCredentials)));
                DiscoveryCodingCredentials credentials = new DiscoveryCodingCredentials { Username = username.Trim().ToLower(), Password = password.Trim() };
                HttpContent content = new ObjectContent<DiscoveryCodingCredentials>(credentials, "application/xml", new List<MediaTypeFormatter> {formatter });
                // new ObjectContent<String>(credentials);
                String baseUri = ConfigurationManager.AppSettings["baseServicesUrl"] + "Authentication/Login";
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, baseUri);
                HttpResponseMessage response = client.Post(baseUri, content

 the thing is apparently I even have to do it for even native c# types such as strings as well.  I have checked out Glenn Block's posting about setting the formatters using config settings or DataContractFormat but apparently these are not working.  the above code does not work obviously for web operations that return IQueryable<T> objects as is possible as shown in the samples provided.  But try as I might I cannot return an IQueryable even for a string.