繁体   English   中英

在WCF REST服务上找不到404

[英]404 not found on WCF REST service

我已经在WCF服务上配置了REST。 我有另一个像这样工作的项目,并将所有配置和内容从其复制到我的项目中。 但是当我运行它时,找不到rest方法和/ web页面。

Web.config:

> <appSettings>
>     <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />   </appSettings>   <system.web>
>     <compilation debug="true" targetFramework="4.5" />
>     <httpRuntime targetFramework="4.5"/>   </system.web>   <system.serviceModel>
>     <services>
>       <service name="WcfRestTest.Service1">
>         <clear />
>         <endpoint behaviorConfiguration="RFEndPointBehavior" binding="webHttpBinding"
>           contract="WcfRestTest.IService1" listenUriMode="Explicit">
>         </endpoint>
>       </service>
>     </services>
>     <behaviors>
>       <endpointBehaviors>
>         <behavior name="RFEndPointBehavior"  >
>           <webHttp helpEnabled="true"/>
>         </behavior>
>       </endpointBehaviors>
>     </behaviors>
>     <protocolMapping>
>       <add binding="basicHttpsBinding" scheme="https" />
>     </protocolMapping>
>     <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />   </system.serviceModel>  
> <system.webServer>
>     <modules runAllManagedModulesForAllRequests="true"/>
>     <directoryBrowse enabled="true"/>   

服务等级:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
    public List<Student> GetStudentDetails()
    {
        List<Student> stuList = new List<Student>();
        stuList.Add(new Student { ID = "1", Name = "Test" });
        return stuList;
    }
}

服务合同:

[ServiceContract]
    public interface IService1
    {
        [OperationContract]
        [WebGet(UriTemplate = "Students", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
        List<Student> GetStudentDetails();
    }

[DataContract]
public class Student
{
    [DataMember]
    public string ID { get; set; }
    [DataMember]
    public string Name { get; set; }
}

我对您的代码段进行了处理,发现它很好用。 我认为您访问的地址有问题。
对于IIS中托管的WCF Rest服务,我们应该使用IIS基址和UriTemplate属性,

[WebGet(UriTemplate = "Students", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]

例如,这是IIS中的以下站点绑定。
在此处输入图片说明
服务的基本地址为http:// MyIP:11000 / service1.svc ,并且应该使用http:// MyIP:11000 / service1.svc / Students路由操作。
必须注意的另一件事是该服务通常具有一个相对地址。 假设存在以下定义。

<endpoint address="myservice" binding="webHttpBinding" contract="WcfService3.IService1" listenUriMode="Explicit"></endpoint>

还应该考虑到它。
http:// MyIP:11000 / service1.svc / myservice / Students
请随时告诉我是否有什么我可以帮助的。

更新

<system.serviceModel>
<services>
  <service name="WcfRestTest.Service1">
    <clear />
    <endpoint behaviorConfiguration="RFEndPointBehavior" binding="webHttpBinding"
      contract="WcfRestTest.IService1" listenUriMode="Explicit">
    </endpoint>
  <endpoint address="" binding="webHttpBinding" contract="WcfRestTest.IService1" behaviorConfiguration="RFEndPointBehavior" bindingConfiguration="mybinding"></endpoint>
  </service>
</services>
<bindings>
  <webHttpBinding>
    <binding name="mybinding">
      <security mode="Transport">
        <transport clientCredentialType="None"></transport>
      </security>
    </binding>
  </webHttpBinding>
</bindings>
<behaviors>
  <endpointBehaviors>
    <behavior name="RFEndPointBehavior"  >
      <webHttp helpEnabled="true"/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM