在阅读了更多关于它的内容并尝试实现wshttpbinding之后,它就不会发生了。无论我尝试什么,我都会得到下面的错误消息(安全模式被注释掉了)。我理解其中的原因,因为绑定之间的SOAP版本不同。
"(415)无法处理消息,因为内容类型'application/soap+xml;charset=utf-8‘不是预期的类型'text/xml;charset=utf-8'“
我在下面的链接中了解了更多关于TransportWithMessageCredentials的信息:
http://msdn.microsoft.com/en-us/library/ms789011.aspx
但是仍然不能让它工作。
我可以在内部应用程序中很好地使用basicHttpBinding,并且工作得很好(如果我不包含任何事务),但我的应用程序仍然需要支持事务(见下文),从这一点我了解到basicHttpBinding不支持,因为它不包含transactionflow属性。
[OperationContract]
[TransactionFlow(TransactionFlowOption.Allowed)]
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))当我尝试在包含安全模式的情况下运行下面的代码时,svc配置编辑器甚至没有启动,并抛出以下错误:"System.InvalidOperationException:找不到与绑定WSHttpBinding的端点的https方案匹配的基地址。注册的基地址方案是http。“
我知道它需要某种SSL/https安全性,但我的网站(如下所示)是http。这对于面向公众的网站来说是很好的,但对于内部网站来说,目前,我想做的就是支持交易。
下面是我对wsHttpBinding的服务器端设置:
<bindings>
<wsHttpBinding>
<binding name="WsHttpBinding_IYeagerTechWcfService" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="24.20:31:23.6470000" sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transactionFlow="true">
<security mode="Transport" >
<transport clientCredentialType = "Windows" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<?xml version="1.0"?>
<services>
<clear />
<service name="YeagerTechWcfService.YeagerTechWcfService">
<endpoint address="" binding="wsHttpBinding" contract="YeagerTechWcfService.IYeagerTechWcfService" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://abc.com/yeagerte/YeagerTechWcfService.YeagerTechWcfService.svc" />
</baseAddresses>
</host>
</service>
</services>这是我的客户端设置:
<?xml version="1.0"?>
<client>
<endpoint address="http://abc.com/yeagerte/YeagerTechWcfService.YeagerTechWcfService.svc"
binding="wsHttpBinding" contract="YeagerTechWcfService.IYeagerTechWcfService"
name="WsHttpBinding_IYeagerTechWcfService" />
</client>有没有人能提供以下信息:
有没有其他方法来支持WCF for basicHttpBinding中的事务,或者任何其他方式?
如果是这样,我该如何实现它?
如果没有,我有什么选择?
对于上面的问题,我可能已经找到了答案,但我想让更有经验的人来运行它。
不让WCF层处理事务(如上所述),我建议在控制器中使用basicHttpBinding和以下代码,当它将数据传递到WCF层时:
// method here
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
{
db.EditCategory(cat);
// the above code would execute the EditCategory method below in the WCF layer and keep the transaction alive ts.Complete();
ts.Dispose();
}
return Json(new GridModel(db.GetCategories()));
// end methodWCF层:
public void EditCategory(Category cat)
{
try
{
using (YeagerTechEntities DbContext = new YeagerTechEntities())
{
Category category = new Category();
category.CategoryID = cat.CategoryID;
category.Description = cat.Description;
// do another db update here or in another method...
DbContext.Entry(category).State = EntityState.Modified;
DbContext.SaveChanges();
}
}
catch (Exception ex)
{
throw ex;
}
}对于使用SSL的面向公众的网站,我如何正确地实现wsHttpBinding?
发布于 2015-07-22 13:06:19
我在使用WCF事务时遇到了同样的问题,我将消息安全与Windows身份验证结合使用,并且不必设置任何证书。
<wsHttpBinding>
<binding name="WSHttpBinding_Transactional"
transactionFlow="true">
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None" />
</security>
</binding>
</wsHttpBinding>https://stackoverflow.com/questions/12272595
复制相似问题