Web应用程序中的WCF服务无法通过RESTCLIENT工作?

时间:2021-03-27 19:47:52

I have added a RESTful WCF service inside a Web application(Righclicked solution and added WCF service) and while running it is exposing the url as svcutil.exe http://localhost:62783/Service1.svc?wsdl but i have tried calling that service UriTemplate from a RESTCLIENT like http://localhost:62783/AuthenticateUser it is throwing an error like

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

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.

HTTP 404.您正在查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下网址,并确保拼写正确。

But if i create a seperate RESTful WCF service and calling from a RESTCLIENT is working fine.Here is my code

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

 [OperationContract]
        string AuthenticateUser1();

and

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

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

and config

和配置

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

Any suggestion??

有什么建议??

1 个解决方案

#1


2  

Based on your posted config, you have a default endpoint for SOAP of basicHttpBinding, which is (by default) mapped to the http scheme. I've done very little with REST, but I believe you will need to add an endpoint using webHttpBinding to do REST, and most likely the URL will need to be http://localhost:62783/Service1.svc/AuthenticateUser (note the inclusion of the service file), though I'm not 100% sure on that one.

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

To add a REST endpoint, do something like this in your service's config file:

要添加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>

Again, REST is not my strong point, but this should hopefully get you pointed in the right direction at least.

同样,REST不是我的强项,但这应该有希望让你至少指向正确的方向。

#1


2  

Based on your posted config, you have a default endpoint for SOAP of basicHttpBinding, which is (by default) mapped to the http scheme. I've done very little with REST, but I believe you will need to add an endpoint using webHttpBinding to do REST, and most likely the URL will need to be http://localhost:62783/Service1.svc/AuthenticateUser (note the inclusion of the service file), though I'm not 100% sure on that one.

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

To add a REST endpoint, do something like this in your service's config file:

要添加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>

Again, REST is not my strong point, but this should hopefully get you pointed in the right direction at least.

同样,REST不是我的强项,但这应该有希望让你至少指向正确的方向。