【问题标题】:Got 404 when consume WCF in REST mode在 REST 模式下使用 WCF 时得到 404
【发布时间】:2012-07-25 05:10:26
【问题描述】:

我在浏览器中使用了这个 url,我希望看到一个 XML,我只得到 404 not found 错误。你能帮忙吗?

--http://SomeIP:65001/WCFPilot/Service1/REST/GetData

web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
        <authentication mode="Windows" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="WCFPilot.Service1">
        <endpoint address="REST" binding="webHttpBinding" contract="WCFPilot.IService1" behaviorConfiguration="REST">          
        </endpoint>

      </service>

    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="REST">
          <webHttp faultExceptionEnabled="true" helpEnabled="true" />          
        </behavior>

      </endpointBehaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>

</configuration>

服务合同

 [ServiceContract]
    public interface IService1
    {

        [OperationContract]
        [WebGet(ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GetData")]
        string GetData();


    }

谢谢

【问题讨论】:

  • 服务器代码是否正在运行?您正在使用端口 65001,这建议您使用 WebDev 来托管您的服务器代码。它应该正在运行,并且应该配置为使用该端口。 (只是先检查一下,但我假设你已经这样做了。)
  • 不,它是 IIS7.5,它正在使用 default.htm

标签: wcf wcf-rest


【解决方案1】:

服务的 URL 应该是

http://SomeIP:65001/Service1.svc/REST/GetData

【讨论】:

    猜你喜欢
    • 2011-05-31
    • 2020-02-03
    • 1970-01-01
    • 1970-01-01
    • 2012-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多