【发布时间】:2017-07-03 03:43:27
【问题描述】:
我被分配了一个当前使用 WCF 服务的旧项目。
重点是更新(更像是重新开始)项目以使用 ASP.NET MVC5 和 Web API。问题是第 3 方使用 WCF 服务,他们可能不愿意对通信结束进行更改。
该项目的主要功能有两个基本,一个是接收数据,保存并仅显示几个主题和历史图表的最后状态,另一个是发送数据(打开/关闭主题)。
我的想法是按原样维护 WCF 服务(接收/发送/保存数据),只需将其添加到由 MVC 和 Web API(读取数据)组成的新解决方案中。 他们需要(我认为)在同一个项目中,因为最终目标是尽可能在 WCF 服务上实现 SignalR。
主要问题是 MVC 和 WebAPI 将保留身份验证,但 WCF 不会。当我尝试在同一个项目上测试 WCF 时,它失败了,因为它要求“登录”。
错误:无法从 http://localhost:50598/ServiceTest.svc 如果这是 Windows (R) 请访问您有权访问的通信基础服务 检查您是否已在指定位置启用元数据发布 地址。有关启用元数据发布的帮助,请参阅 MSDN 文档位于 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata交流 错误 URI:http://localhost:50598/ServiceTest.svc 元数据包含 无法解决的参考: 'http://localhost:50598/ServiceTest.svc'。内容类型 text/html; charset=utf-8 响应消息的内容类型不匹配 绑定(应用程序/soap+xml;charset=utf-8)。如果使用 自定义编码器,请确保 IsContentTypeSupported 方法是 正确实施。响应的前 1024 个字节是:'?
登录。
用户名http://localhost:50598/ServiceTest.svc HTML文档没有 包含 Web 服务发现信息。
我尝试了所有可以在网络上找到的东西。但找不到任何可行的方法。
我的最后一次是摆弄 web.config:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="UnsecuredBinding">
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="Management.ServiceAspNetAjaxBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="Management.ServiceTest" behaviorConfiguration="serviceBehavior">
<endpoint address="" behaviorConfiguration="Management.ServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="ServiceLibrary.IService" bindingConfiguration="UnsecuredBinding"/>
</service>
</services>
</system.serviceModel>
我还将 routes.IgnoreRoute 添加到 RouteConfig.cs
routes.IgnoreRoute("{resource}.svc/{*pathInfo}");
routes.IgnoreRoute("{resource}.svc");
并尝试将其添加到 Global.asax
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
HttpApplication context = (HttpApplication)sender;
if (context.Request.Url.ToString().Contains(".svc"))
{
context.Response.SuppressFormsAuthenticationRedirect = true;
}
}
我的问题:
如果我将 WCF 方法迁移到 WebAPI,客户端是否需要对其进行任何修改?
如果是,我如何将 WCF 集成到我的 MVC/WebAPI 项目中,而不受登录障碍的影响。
【问题讨论】:
标签: c# asp.net asp.net-mvc wcf asp.net-web-api