【问题标题】:Restful WCF can't reach operationcontractRestful WCF 无法达到 operationcontract
【发布时间】:2017-12-26 06:44:14
【问题描述】:

我创建了一个 RESFTful WCF Web 服务,并将它作为一个新的 Web 应用程序安装在 IIS 中。 WCF 有一些操作,例如:LogingetEmployees ...等。当我从 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 上运行,知道什么是问题吗?我错过了什么吗?

【问题讨论】:

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


    【解决方案1】:

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

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

    所以在 IIS 中,url 将是http://myserver/service.svc/rest/getEmployees?name=dada

    更新:

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

    【讨论】:

    • 成功了!!!!感谢您的回答,但是我想知道我是否可以避免 url 中的 svc 文件,它看起来并不专业:) 可能类似于:myserver/rest/getEmployees?name=dada,这可能吗?
    猜你喜欢
    • 2010-10-09
    • 1970-01-01
    • 2016-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-18
    • 2013-01-15
    • 1970-01-01
    相关资源
    最近更新 更多