I'm trying to consume a SOAP service using WCF in .NET 5. The service provider expects the content type of the request to be text/xml
but sends a response with content type application/xml
.
The following code throws a ProtocolException
because is expects both request and response to have content type text/xml
.
var binding = new BasicHttpBinding();
var endpoint = new EndpointAddress("http://[...]/inquiry");
var channelFactory = new ChannelFactory<InquiryServiceSoapPort>(binding, endpoint);
var serviceClient = channelFactory.CreateChannel();
var inquiry = new Inquiry();
var result = serviceClient.createInquiry(inquiry);
I was able to change the content type to application/xml
using a custom encoder, but that changes it for both request and response, and my request then is rejected by the server.
Is there a way to change the content type of the response only?
Edit
I am writing client-side code, not server-side code, mind you. As of now, it seems I can only catch and swallow the exception or re-implement the code either using another framework or from scratch.