【问题标题】:Error moving WCF service from dev machine to server将 WCF 服务从开发机器移动到服务器时出错
【发布时间】:2014-05-18 23:05:27
【问题描述】:

这是一个 WCF REST 服务。该服务在我的开发机器上运行良好。

我在 wwwroot 的名为 Services\ 的子文件夹中有服务文件

诚然,我很擅长编写代码,但不擅长使用 IIS 来托管/发布我们的服务。

我试图做的只是将服务文件夹从我的开发笔记本电脑复制到服务器的 wwwroot 文件夹。

当发生这种情况并且我尝试访问服务器上的服务时,我收到了一些我不理解的奇怪错误(好吧,我有点理解它只是不知道为什么会这样)

“找不到类型'BooksService.Service1',作为ServiceHost指令中的Service属性值提供,或在配置元素system.serviceModel/serviceHostingEnvironment/serviceActivations中提供。”

Service1.cs 在我的项目中看起来像这样:

namespace BooksService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
    public class Service1 : IDataService

我的 web.config 有相当一部分是基于 google 推荐的,所以我可能不理解某些内容或者只是搞错了。

Web.Config 看起来像:

***<?xml version="1.0"?>
<configuration>
  <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="BooksService.Service1">
        <endpoint address="" binding="webHttpBinding" contract="BooksService.IDataService" behaviorConfiguration="restfulBehavior"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/bookservice" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="restfulBehavior">
          <webHttp />
        </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="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>***

我的服务文件如下所示:

然后有一个包含我的 .dll 的 bin 文件夹

所以文件夹布局如下:

c:\inetpub\wwwroot\SERVICES\BookService\bin

service.svc 在 BookService 文件夹中,程序集在 bin 文件夹中。

我可能会遗漏哪些步骤?

【问题讨论】:

  • 1.您是否确认服务器上安装了相同级别的 IIS/.net 等? 2.您有任何安全问题吗?运行 svc 等的用户/身份是否相同。这些是首先要检查的内容
  • 感谢您的回复。我知道该服务正在运行 IIS 7.0。相对确定开发机器也是如此。关于运行 svc 的相同用户/身份,您能详细说明一下吗?在我的开发机器上登录和在服务器上登录都是管理员登录。我应该在 IIS 中配置什么来解决这个问题吗?
  • 谢谢,我特别想的是App Pool identities

标签: c# .net web-services wcf service


【解决方案1】:

首先,您需要在 IIS 中创建一个应用程序并将虚拟目录指向您的应用程序文件夹:c:\inetpub\wwwroot\SERVICES\BookService。

那么你需要相应地更新你的服务基地址:

<baseAddresses>
     <add baseAddress="http://localhost/services/bookservice" />
 </baseAddresses>

您可以通过在浏览器中输入网址并浏览到服务位置来测试该网址。

【讨论】:

  • 谢谢!就是这样。如此简单......我应该看到这个。
猜你喜欢
  • 1970-01-01
  • 2021-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-18
相关资源
最近更新 更多