2016-07-07 90 views
0

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

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

的Web.config WCF

<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); 
} 
+0

您是否可以用了SoapUI,得到的结果里面? –

+0

您没有“APGame.Contracts.IGameService”合同。 – granadaCoder

+0

@granadaCoder我确实有IGameService的合同,并且工作得很好。我试图创建一个新的服务或新的服务合同,作为ajax w/AngularJS的REST风格的服务工作 –

回答

0

我已经尝试了许多不同的解决方案(比如这个:404 when running .net 4 WCF service on IIS (no svc file)),并没有一次成功。

我意识到问题在于它是通过HTTPS访问的。尽管我可以访问.svc文件(https://localhost/APGame.WebHost/PlayService.svc),但我无法访问任何方法(例如:/Playservice.svc/json/2)。为了解决这个问题,我增加了以下我的web.config中的<bindings>标签

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

然后我加入bindingConfiguration="webBinding"我的服务端点