C# IIS赢得';t激活WCF服务,404错误

C# IIS赢得';t激活WCF服务,404错误,c#,wcf,iis-7.5,C#,Wcf,Iis 7.5,我有一个只公开HTTP端点的WCF服务,我的App.config如下: <?xml version="1.0" encoding="utf-8"?> <configuration> <system.diagnostics> <sources> <source name="System.ServiceModel" switchValue="Informatio

我有一个只公开HTTP端点的WCF服务,我的App.config如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>  
  <system.diagnostics>
      <sources>
            <source name="System.ServiceModel" 
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
            <listeners>
               <add name="traceListener" 
                   type="System.Diagnostics.XmlWriterTraceListener" 
                   initializeData= "C:\Users\Developer\Documents\ProjectName\Servicelog.svclog" />
            </listeners>
         </source>
      </sources>
   </system.diagnostics>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" />
    <services>
      <service name="Project.ServiceOne">
        <endpoint address="http://localhost/Project/ServiceOne" binding="webHttpBinding" contract="Project.IServiceOne"/>
      </service>
      <service name="Project.ServiceTwo">
        <endpoint address="http://localhost/Project/ServiceTwo" binding="webHttpBinding" contract="Project.IServiceTwo"/>
      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
   <httpProtocol>
     <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept"/>
     </customHeaders>
   </httpProtocol>
  </system.webServer>
  <startup>
    <supportedRuntime version="v2.0.50727" />
  </startup>
</configuration>

您需要设置正确的行为:

<services>
  <service name="Project.ServiceOne" behaviorConfiguration="serviceBehavior">
    <endpoint address="" binding="webHttpBinding" contract="Project.IServiceOne" behaviorConfiguration="webBehaviour"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
    <host>
      <baseAddresses>
        <add baseaddress="http://localhost/Project/ServiceOne">
      </baseAddresses>
    </host>
  </service>
  <service name="Project.ServiceTwo" behaviorConfiguration="serviceBehavior">
    <endpoint address="" binding="webHttpBinding" contract="Project.IServiceTwo" behaviorConfiguration="webBehaviour"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
    <host>
      <baseAddresses>
        <add baseaddress="http://localhost/Project/ServiceTwo">
      </baseAddresses>
    </host>
  </service>    
</services>
<behaviors>
    <serviceBehaviors>
        <behavior name="serviceBehavior">         
          <serviceMetadata httpGetEnabled="true"/>        
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
        <behavior name="webBehaviour">
          <webHttp/>
        </behavior>
    </endpointBehaviors>
</behaviors>


你能给我们看一下你装饰过的界面吗?@RealityDysfunction发布了一个简化版本:界面中的所有方法都有相同的注释,配置方式几乎相同。我不熟悉与WCF通信的GET方法,因为你经常需要调整UriTemplate使其工作,实际上,使用POST方法更容易使其工作。如果您将方法更改为POST并取出UriTemplate,但它仍然不起作用,那么问题就出在web.config上。它以前是POST,我将其设置为GET,以便使用普通浏览进行测试。我不认为您可以通过这种方式设置端点地址并发布到该URL。RESTful WCF仍然需要在URL中包含.svc,然后您可以使用URL重写来删除.svc。
<services>
  <service name="Project.ServiceOne" behaviorConfiguration="serviceBehavior">
    <endpoint address="" binding="webHttpBinding" contract="Project.IServiceOne" behaviorConfiguration="webBehaviour"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
    <host>
      <baseAddresses>
        <add baseaddress="http://localhost/Project/ServiceOne">
      </baseAddresses>
    </host>
  </service>
  <service name="Project.ServiceTwo" behaviorConfiguration="serviceBehavior">
    <endpoint address="" binding="webHttpBinding" contract="Project.IServiceTwo" behaviorConfiguration="webBehaviour"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
    <host>
      <baseAddresses>
        <add baseaddress="http://localhost/Project/ServiceTwo">
      </baseAddresses>
    </host>
  </service>    
</services>
<behaviors>
    <serviceBehaviors>
        <behavior name="serviceBehavior">         
          <serviceMetadata httpGetEnabled="true"/>        
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
        <behavior name="webBehaviour">
          <webHttp/>
        </behavior>
    </endpointBehaviors>
</behaviors>