asp.net - Restful WCF无法达到操作合约

标签 asp.net wcf wcf-data-services wcf-rest

我创建了一个 RESFTful WCF Web 服务,并将其作为新的 Web 应用程序安装在 IIS 中。 WCF 有一些操作,例如:登录getEmployees ...等。当我从 vs 发布并运行它时,它工作正常,因此我可以通过浏览器链接进行访问,例如:

http://myserver/service.svc
http://myserver/service.svc?wsdl
http://myserver/Login?user=sample&password=paswd
http://myserver/getEmployees?name=dada

通过操作链接,我可以获得所需的确切数据作为响应。

但是,只有当我从 vs 运行 Web 服务时它才有效,但是当我尝试从浏览器访问链接并且 Web 服务未在 VS 中运行时,我只能访问如下链接:

http://myserver/service.svc
http://myserver/service.svc?wsdl

但不是操作链接,例如:

http://myserver/Login?user=sample&password=paswd
http://myserver/getEmployees?name=dada

端点配置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings/>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="AXPAYROLL.PayrollActions" behaviorConfiguration="serviceBehavior">
        <endpoint address="http://myserver/" behaviorConfiguration="RESTFriendly" binding="webHttpBinding" contract="AXPAYROLL.IPayrollActions">
          <identity>
            <dns value="myserver" />
          </identity>
        </endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://myserver/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="RESTFriendly">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="serviceBehavior">
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="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" />
          <serviceAuthorization serviceAuthorizationManagerType="AXPAYROLL.DataContractLayer.DistributorValidator, AXPAYROLL" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

我还创建了一个控制台主机应用程序,其中一切都像 vs 一样运行良好,因此 IIS 中的问题肯定可能出在权限上......

我是 WCF 新手,但我相信这不是正确的运行方式,而不是始终部署 WCF!我还想在没有安装 vs 的生产服务器上安装 wcf,我知道可以通过控制台应用程序实现自托管,但这又不是我想要的,我希望它在正常的 iis 上运行,知道什么吗是问题吗?我错过了什么吗?

最佳答案

当WCF服务在IIS上时,<baseAddresses>中指定的任何基地址将被忽略,基地址将是 .svc 文件的 URL。

address端点元素中的属性是相对地址,可能类似于 address="rest" .

因此在 IIS 中,URL 将为 http://myserver/service.svc/rest/getEmployees?name=dada

更新:

要删除 svc 扩展,请查看 this question

关于asp.net - Restful WCF无法达到操作合约,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45216911/

相关文章:

c# - Web 服务 VS。 Aspx 页面 : Pros and Cons

c# - 我可以在保存更改之前验证实体吗?

c# - 命名空间 'Linq' 中不存在类型或命名空间名称 'System'

c# - 将 ViewModel 与包含 HttpPostedFileBase 的 ViewModel 列表绑定(bind)到 Controller 操作

wcf - 在互联网上发布的wcf服务有 'You have created a service'页面是不是很糟糕?

wcf - 如何使用 Fiddler 监听 asp.net 开发服务器(即 cassini)?

c# - 通过 ADO.NET 数据服务重用现有类型

c# - 有没有办法在 OData 中说 "Expand Everything"?

c# - ASP.NET 应用程序可扩展性最佳实践指南

c# - 从 Windows 身份验证中获取 `ICredentials`