繁体   English   中英

将WCF服务从开发机移动到服务器时出错

[英]Error moving WCF service from dev machine to server

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

我将服务文件放在wwwroot的子文件夹中,称为Services \\

诚然,我对编写代码非常精通,但是对于使用IIS托管/发布我们的服务却不那么精通。

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

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

“找不到类型'BooksService.Service1',在ServiceHost指令中作为服务属性值提供,或在配置元素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>***

我的服务文件如下所示:

<%@ServiceHost Service =“ BooksService.Service1”%>

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

因此,文件夹布局如下:

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

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

我可能缺少什么步骤?

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

然后,您需要相应地更新服务基本地址:

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

您可以通过在浏览器中键入URL并浏览到服务位置来测试URL。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM