【问题标题】:WCF service inside a Web application is not working through RESTCLIENT?Web 应用程序中的 WCF 服务不能通过 RESTCLIENT 工作?
【发布时间】:2013-12-17 06:04:46
【问题描述】:

我在 Web 应用程序中添加了一个 RESTful WCF 服务(Righclicked 解决方案并添加了 WCF 服务),并且在运行它时将 url 公开为 svcutil.exe http://localhost:62783/Service1.svc?wsdl 但我尝试从像 http://localhost:62783/AuthenticateUser 这样的 RESTCLIENT 调用该服务 UriTemplate正在抛出类似

的错误

HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

但如果我创建一个单独的 RESTful WCF 服务并从 RESTCLIENT 调用工作正常。这是我的代码

 [OperationContract]
        string AuthenticateUser1();

和

 [WebInvoke(UriTemplate = "/AuthenticateUser", Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
        public string AuthenticateUser1()
        {

            return string.Format("Token {0}", new Guid().ToString());
        }

和配置

 <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

有什么建议吗??

【问题讨论】:

  • 你提供的AuthenticateUser1方法是Service1.svc的一部分吗?
  • 是的,它是 Service1.SVC 的一部分
  • 你的服务主机的 bindingAddress 是什么?

标签: c# asp.net wcf restful-url rest-client


【解决方案1】:

根据您发布的配置,您有一个默认的 SOAP 端点 basicHttpBinding,它(默认情况下)映射到 http 方案。我对 REST 所做的很少,但我相信您需要使用 webHttpBinding 添加一个端点来执行 REST,并且很可能 URL 需要为 http://localhost:62783/Service1.svc/AuthenticateUser(请注意包含服务文件),不过我不是 100% 确定那个。

要添加 REST 端点,请在服务的配置文件中执行以下操作:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="false" />
      </behavior>
    </serviceBehaviors>
    <!-- Added for REST -->
    <endpointBehaviors>
      <behavior name="REST">
        <webHttp />
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <!-- REST endpoint -->
  <endpoint address="" binding="webHttpBinding"
            contract="<contract name with namespace>"
            behaviorConfiguration="REST"> 
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

再说一遍,REST 不是我的强项,但希望这至少能让你找到正确的方向。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-21
  • 1970-01-01
相关资源
最近更新 更多