2013-10-16 76 views
0

我正在使用WCF服務庫創建Windows服務,以開發PIC32單片機和Windows平臺之間用於發送和接收數據的基於TCP的通信。方法必須具有返回類型WCF服務

我app.config文件是

<?xml version="1.0" encoding="utf-8" ?> 
<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 behaviorConfiguration="WcfServiceLibrary1.Service1Behavior" name="WcfServiceLibrary1.Service1"> 
     <endpoint address="" binding="netTcpBinding" bindingConfiguration="" 
      contract="WcfServiceLibrary1.IService1"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" 
      contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:8523/Service1" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WcfServiceLibrary1.Service1Behavior"> 
      <serviceMetadata httpGetEnabled="false" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 

</configuration> 

和C#Codefor service1.cs文件

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Diagnostics; 
using System.Linq; 
using System.ServiceProcess; 
using System.Text; 
using System.ServiceModel; 
using WcfServiceLibrary1; 

namespace WindowsService1 
{ 
    public partial class Service1 : ServiceBase 
    { 
     internal static ServiceHost myServiceHost = null; 
     public WCFServiceHost1() 
     { 
      InitializeComponent(); 
     } 

     protected override void OnStart(string[] args) 
     { 
      if (myServiceHost != null) 
      { 
       myServiceHost.Close(); 
      } 
      myServiceHost = new ServiceHost(typeof(Service1)); 
      myServiceHost.Open(); 
     } 

     protected override void OnStop() 
     { 
      if (myServiceHost != null) 
      { 
       myServiceHost.Close(); 
       myServiceHost = null; 
      } 
     } 
    } 
} 

public WCFServiceHost1()方法必須返回類型現在我得到錯誤。

我不明白爲什麼我有這個錯誤。我現在在WCF中,並且我通過msdn中提供的信息做到了這一點。

回答

3

我想你想聲明的構造函數:應該有返回類型

public Service1() 
{ 
    InitializeComponent(); 
} 

但是,你必須聲明的方法(也有可能是無效):

public WCFServiceHost1() 
{ 
    InitializeComponent(); 
} 

,如果它總結是一個構造函數,它應該是public Service1()(與類型名稱相同),如果它是一種方法,它應該是public void WCFServiceHost1()

+0

它的工作...謝謝噸.. – SPandya

相關問題