2012-03-26 20 views
0

我正在手動創建一個WCF服務,它將充當DAL並創建了多個項目來隔離核心功能,並且希望通過將託管的MiscServices.svc訪問數據(此架構還將支持多個主機) 。該解決方案的層次結構如下(每一個獨立的項目):嘗試手動配置WCF主機時需要聲明 - 如何解決?

  • 模型(實體集)
  • 服務合同(接口):IMiscContracts.cs
  • 服務庫(類):MiscServices.cs:IMiscContracts
  • 主機(.SVC文件):MiscServices.svc

MiscServices.svc:

<%@ ServiceHost Language="C#" Debug="true" Service="MyProject.DAL.DB1.Service.MiscServices" CodeBehind="MyProject.DAL.DB1.Service.MiscServices.cs" %> 

。包含.svc的Hosts項目中引用了合同和.Services。

項目只有MiscServices.svc和一個web.config:

<system.serviceModel> 
    <services> 
     <service name="MyProject.DAL.DB1.MiscServices"> 
     <endpoint name ="MiscServicesEndpoint" 
        address="MiscServices.svc" 
        binding="wsHttpBinding" 
        contract="MyProject.DAL.DB1.Contracts.IMiscContracts" /> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>   
     </service> 
    </services> 

MiscServices.cs:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.ServiceModel; 
using System.ServiceModel.Web; 
using MyProject.DAL.DB1.Contracts; 
using MyProject.DAL.DB1.Models; 


namespace MyProject.DAL.DB1.Services 
{ 
    /// <summary> 
    /// Interface implementations 
    /// </summary> 
    public class MiscServices : IMiscContracts 
    { 

     private DB1DBContext dbContext = new DB1DBContext(); 

     /// <summary> 
     /// Returns a simple input string 
     public string GetString(string someString) 
     { 
      return String.Format("This is your string {0}", someString); 
     } 
. 
. 
. 

的問題是,當我嘗試發佈主機項目,我得到以下錯誤:

'If', 'ElseIf', 'Else', 'End If', 'Const', or 'Region' expected. 
Declaration expected. 

...對於.svc文件中的一行,我不確定如何更改等等。

+0

那麼MiscServices.cs中有什麼? – 2012-03-26 21:50:57

+0

@degorolls - 添加了MiscServices.cs的代碼示例,但我不明白這是怎麼回事。 – ElHaix 2012-03-27 13:51:23

+0

錯誤文本似乎暗示VB.NET解析器正在嘗試處理您的代碼。不確定會如何發生,請添加整個錯誤(如果可用,請添加堆棧跟蹤)。整個錯誤內容可能有線索。 – 2012-03-27 17:15:56

回答

0

看來問題在VS維護的項目類型中。

我刪除了項目,創建了一個全新的WCF服務項目,刪除了界面和類,只留下了.svc文件,它工作得很好。

相關問題