2013-10-16 73 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

相关问题