我想使用tfs事件注册来读取BuildQualityChanged和WorkItemChanged事件。它在几个月前工作,现在我在获取事件xml时遇到以下错误:
HTTP代码415:无法处理消息,因为内容类型为'application / soap + xml; charset = utf-8'不是预期的类型'text / xml;字符集= UTF-8' 。 ---> System.Net.WebException:远程服务器返回错误:(415)无法处理消息,因为内容类型为'application / soap + xml; charset = utf-8'不是预期的类型'text / xml;字符集= UTF-8' ..
我正在构建一个控制台应用程序,该应用程序稍后将成为Windows服务。托管wcf服务的代码如下:
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);
}
我发现此错误的所有解决方案确实在web.config中配置了服务,这对我来说是不可能的解决方案,我必须以编程方式进行托管。我找到的第二个解决方案是使用BasicHttpBinding而不是CustomBinding,但这对我来说也不起作用,tfs会出现相同的错误。我想知道使用BasicHttpBinding的WSDL中的SOAP版本也是SOAP 1.2。使用BasicHttpBinding的SetBinding()是
var binding1 = new BasicHttpBinding();
binding1.Name = "binding1";
binding1.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding1.Security.Mode = BasicHttpSecurityMode.None;
_host.AddServiceEndpoint(typeof(TFS.Build.ITeamFoundationEventSubscriber), binding1, serviceUri);
必需和给定请求的唯一区别是内容类型,我需要application / soap + xml而不是application / xml
谁能告诉我我的大脑出了什么问题?
迈克尔
答案 0 :(得分:1)
经过几个小时的搜索,我没有找到任何解决方案。一个微软的极客帮助我摆脱它:
TFS2010仅支持没有安全性的wsHttpBinding
我的SetBinding()方法的内容现在如下:
var binding1 = new WSHttpBinding();
binding1.Name = "binding1";
binding1.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding1.Security.Mode = SecurityMode.None;
_host.AddServiceEndpoint(typeof(TFS.Build.ITeamFoundationEventSubscriber), binding1, GetCorrectServiceAddress());
MAGIC,IT WORKS:)