So, I used a wsdl provided for me to generate all my base client code for WCF. When I attempt to communicate with the service, I get an error. The error says that the content type of the binding does not match that of the response message.
After firing up Fiddler, I looked at the raw data going out and coming back. It turns out, the Magento server that I'm attempting to talk to is returning two Content-Type values. Again, using Fiddler, I forced a response to my client with only one Content-Type, and it worked just fine.
Now, I'd like nothing more than to have the Magento server respond properly, as this would be the "correct" solution to this problem. However, that is out of my control (different company that doesn't want to fix it). So, I need to intercept the headers when WCF gets them and have it ignore the duplicate. After searching the interwebs for a while, I'm still trying to figure out the "best" way of doing this. Or "any" way to do this, for that matter.
Anyone able to point me to the right thing to override and what I need to do to remove a superfluous Content-Type?
You should be able to implement an IClientMessageInspector
to manipulate and remove the superfluous Content-Type in the response received from the Magento Server in the AfterReceiveReply
method.
EDIT:
So you can access the HTTP headers in the received response via HttpResponseMessageProperty
that is available in
void IClientMessageInspector.AfterReceiveReply(ref Message reply, Object correlationState)
{
var prop =
reply.Properties[HttpResponseMessageProperty.Name] as HttpResponseMessageProperty;
if (prop != null)
{
// get the content type headers
var contentType = prop.Headers["Content-Type"];
}
}
however, Content-Type appears to be a restricted header. Perhaps a little reflection may solve the issue, but hopefully this gives you some ideas.