簡體   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