簡體   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