The remote server returned an error: (415) Cannot process the message because the content type 'application / xml' was not the expected type 'application / soap + xml; charset = utf-8 '
I just try to launch my self host. I have 2 endpoints with Basic Authentication. So I had to use wsHttpBinding for that. CreateUser endpoint should use XML format and RemoveUser endpoint - json format.
I attached my selfhost app.config, client main function and contract.
server app.config
<services> <service name="Web.Service.Core.Services.UserContract" behaviorConfiguration="AuthBehavior" > <endpoint address="CreateUser" binding="wsHttpBinding" bindingNamespace="http://localhost/Auth/" contract="Web.Service.Library.Contracts.IUserContract" /> <endpoint address="RemoveUser" binding="wsHttpBinding" contract="Web.Service.Library.Contracts.IUserContract" /> IUserContract.cs
[ServiceContract(Namespace = "http://localhost/Auth/", ProtectionLevel = ProtectionLevel.None)] [XmlSerializerFormat] public interface IUserContract { [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "Auth/CreateUser", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped)] Response CreateUser(Stream xml); [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "Auth/RemoveUser", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)] Response RemoveUser(Stream stream); client main()
var webRequest = (HttpWebRequest) WebRequest.Create(CreateUserUrl); webRequest.Method = "POST"; webRequest.ContentType = "application/xml"; webRequest.ContentLength = data.Length; var rqStream = webRequest.GetRequestStream(); rqStream.Write(data, 0, data.Length); rqStream.Close(); var webResponse = webRequest.GetResponse(); var rsStream = webResponse.GetResponseStream(); var responseXml = new StreamReader(rsStream); var s = responseXml.ReadToEnd(); 
