i want to use tfs event registration for reading out the BuildQualityChanged and the WorkItemChanged event. It was working some month before, now i get the following error while getting the event xml:
HTTP code 415: Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'. ---> System.Net.WebException: The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
Im building a console application which will later be an windows service. The code for for hosting the wcf service is the following:
private void HostWcfService()
{
D_("Hosting WCF service");
var serviceUri = new Uri(GetCorrectServiceAddress());
_host = new ServiceHost(typeof(BuildQualityChanged), new []{serviceUri});
AddBehaviors(_host);
SetBinding(_host, serviceUri);
_host.Open();
}
private static void AddBehaviors(ServiceHost service)
{
var smb = service.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (smb == null)
{
smb = new ServiceMetadataBehavior();
service.Description.Behaviors.Add(smb);
}
smb.HttpGetEnabled = true;
var sdb = service.Description.Behaviors.Find<ServiceDebugBehavior>();
if (sdb == null)
{
sdb = new ServiceDebugBehavior();
service.Description.Behaviors.Add(sdb);
}
sdb.IncludeExceptionDetailInFaults = true;
}
private void SetBinding(ServiceHost _host, Uri serviceUri)
{
// create and configure an MTOM encoder
var mtom =
new TextMessageEncodingBindingElement(
MessageVersion.Soap11, Encoding.UTF8);
// create a CustomBinding using MTOM encoder
CustomBinding binding = new CustomBinding();
binding.Elements.Add(mtom);
binding.Elements.Add(
new HttpTransportBindingElement());
_host.AddServiceEndpoint(typeof(TFS.Build.ITeamFoundationEventSubscriber),
binding, serviceUri);
}
All solutions i found until now with this error does configuring the service in web.config, this is no possible solution for me, i have to host programmatically. The second solution i found is to use BasicHttpBinding rather than CustomBinding, but this does not work too for me, the tfs breaks with the same error. I was wondering that the SOAP Version in the WSDL by using BasicHttpBinding is SOAP 1.2 too. SetBinding() for using BasicHttpBinding is
var binding1 = new BasicHttpBinding();
binding1.Name = "binding1";
binding1.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding1.Security.Mode = BasicHttpSecurityMode.None;
_host.AddServiceEndpoint(typeof(TFS.Build.ITeamFoundationEventSubscriber), binding1, serviceUri);
The only difference in required and given request is the content type, i need application/soap+xml rather than application/xml
Can anyone tell me where my brain is going wrong?
Michael