简体   繁体   English

方法必须具有返回类型WCF服务

[英]Method must have a return type WCF Service

I am creating windows service using WCF service library for developing TCP based communication between PIC32 Microcontroller and Windows platform to send and receive data. 我正在使用WCF服务库创建Windows服务,以开发PIC32单片机与Windows平台之间基于TCP的通信以发送和接收数据。

My app.config file is 我的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>

And the C# Codefor service1.cs file is 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;
            }
        }
    }
}

Now I am getting error in public WCFServiceHost1() that Method must have a return type . 现在,我在public WCFServiceHost1()中遇到错误,该方法必须具有返回类型

I am not getting why I am having this error. 我不明白为什么会有这个错误。 I am now in WCF and I did upto this this by the information provided in the msdn. 我现在在WCF中,并且通过msdn中提供的信息来做到这一点。

I suppose you wanted to declare constructor: 我想您想声明构造函数:

public Service1()
{
    InitializeComponent();
}

However, you have declared method that should have return type (it could also be void): 但是,您已声明应具有返回类型的方法(也可以为空):

public WCFServiceHost1()
{
    InitializeComponent();
}

To sum up if it is a constructor it should be public Service1() (same as type name), if it is a method it should be public void WCFServiceHost1() . 总结一下,如果它是一个构造函数,它应该是public Service1() (与类型名称相同),如果它是一个方法,它应该是public void WCFServiceHost1()

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

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