I'm writing a WCF REST service to receive AWS SNS Notification Message with my WCF REST Service.
However, WCF REST only supports XML and JSON, but because of legacy reasons Amazon SNS posts their notifications with the Content-Type: text/plain; charset=UTF-8 header, according to the Amazon documentation:
POST / HTTP/1.1
Content-Type: text/plain; charset=UTF-8
// ...
{
"Type" : "Notification",
// ...
"UnsubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&..."
}
When I call my service with this "text/plain" content type like Amazon, there is an error which says:
Request Error.
The server encountered an error processing the request. The exception message is 'The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml'; 'Json'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details.'. See server logs for more details.
My current code:
public interface MyServiceInterface
{
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/AmazonIPChanges")]
Task AmazonIPChanges(SNSNotificationMessage data);
}
[DataContract]
public class SNSNotificationMessage
{
[DataMember]
public string Type { get; set; }
// ...
[DataMember]
public string UnsubscribeURL { get; set; }
}
The DataContract maps to the Amazon SNS message. This code is working when I perform a POST with content-type "application/json", but how can I let it accept Amazon's text/plain content-type?