【问题标题】:Configure multiple WCF bindings or services in one config在一个配置中配置多个 WCF 绑定或服务
【发布时间】:2016-07-07 19:26:59
【问题描述】:

我正在尝试在一个 web.config 中使用多个服务。我遇到的问题是,当我转到https://localhost/APGame.WebHost/PlayService.svc/checktraining?g=3 时,我得到资源找不到错误(404)。我曾尝试使用一项服务和多项服务合同来执行此操作,但也没有用。

我可以访问https://localhost/APGame.WebHost/PlayService.svc,以便服务正在运行。我只是不确定我做错了什么。

WCF 的 Web.config

  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="json">
          <webHttp defaultOutgoingResponseFormat="Json" helpEnabled="true" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <services>
      <service name="APGame.Services.GameManager">
        <endpoint address="" binding="wsHttpBinding" contract="APGame.Contracts.IGameService" />
      </service>
      <service name="APGame.Services.PlayManager">
        <endpoint address="" behaviorConfiguration="json" binding="webHttpBinding" contract="APGame.Contracts.IPlayService" />
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding transactionFlow="true" sendTimeout="00:20:00">
          <security mode="Transport">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
      <serviceActivations>
        <add service="APGame.Services.GameManager" relativeAddress="GameService.svc" />
        <add service="APGame.Services.PlayManager" relativeAddress="PlayService.svc" />
      </serviceActivations>
    </serviceHostingEnvironment>
  </system.serviceModel>

服务合同

[ServiceContract]
public interface IPlayService
{
    [OperationContract]
    [WebInvoke(Method = "GET", UriTemplate = "/checktraining?g={groupGameId}")]
    bool? CheckTraining(int groupGameId);
}

【问题讨论】:

  • 你能用 SoapUI 得到结果吗?
  • 您没有“APGame.Contracts.IGameService”合同。
  • @granadaCoder 我确实有 IGameService 的合同,而且工作得很好。我正在尝试创建一个新服务或新服务合同,以作为带有 AngularJS 的 ajax 的 RESTful 服务
  • @EricS 我从未使用过 SoapUI,这是我应该使用的东西吗?
  • 是的,它是一个非常适合测试 Web 服务的工具。它有很多功能。如果您只需要提供数据,SoapUI 可以确认您的服务已启动并正在运行。

标签: c# .net web-services rest wcf


【解决方案1】:

我尝试了很多不同的解决方案(例如这个:404 when running .net 4 WCF service on IIS (no svc file)),但都没有奏效。

我意识到问题在于它是通过 HTTPS 访问的。即使我可以访问.svc 文件(https://localhost/APGame.WebHost/PlayService.svc),之后我也无法访问任何方法(例如:/Playservice.svc/json/2)。为了解决这个问题,我在 &lt;bindings&gt; 标签内的 web.config 中添加了以下内容

  <webHttpBinding>
    <binding name="webBinding">
      <security mode="Transport">
      </security>
    </binding>
  </webHttpBinding>

然后我将bindingConfiguration="webBinding" 添加到我的服务端点

【讨论】:

    猜你喜欢
    • 2013-06-16
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 2011-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多