我自己做 了一个demo,用wcf进行通信,但是客户端代理老是生成不了,宿主用的是 windows服务,在安装windows 服务的时候老是出错,不知道哪的问题   下面是代码:namespace WcfTest
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract(Namespace = "www.huhang360.com/")]
    public interface IService1
    {
        [OperationContract]
        string GetNameString(string Name);               
    }这个是wcf里的代码 namespace WcfTest
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class Service1 : IService1
    {
        User user = new User();
        public string GetNameString(string Name)
        {
            //System.Diagnostics.Debugger.Break();// 去掉注释即可调试服务
            return user.GetName(Name );
        }    }
}
下边是windows服务里 的代码:using WcfTest;namespace WindowsServiceTest
{
    public partial class ServiceHostController : ServiceBase
    {
        private static ServiceHost ServiceControl=null ;
        public ServiceHostController()
        {
            InitializeComponent();
           // this.ServiceName = "自定义服务1";
        }       
        protected override void OnStart(string[] args)
        {
            if ( ServiceControl !=null )
            {
                ServiceControl.Close();
            }
            ServiceControl = new ServiceHost(typeof(Service1));
            ServiceControl.Open();
        }        protected override void OnStop()
        {
            
        }
        
    }
}
最下边是app.config中的配置
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
      <services>
        <service name="WcfTest.ServiceTest"
                 behaviorConfiguration="WcfTest.WcfTestServiceBehavior">
          <host>
            <baseAddresses>
              <add baseAddress="net.tcp://localhost:9000/Services"/>
            </baseAddresses>
          </host>
          <endpoint address="net.tcp://localhost:9000/Services" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IService1" contract="WcfTest.IService1">
          </endpoint>
          <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
        </service>
      </services>
      <bindings>
        <netTcpBinding>
          <binding name="NetTcpBinding_IService1" closeTimeout="00:01:00"
              openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00"
              maxReceivedMessageSize="2147483647"
                >
            <security mode="None" />
          </binding>
        </netTcpBinding>
      </bindings>
      <behaviors>
        <serviceBehaviors>
          <behavior name="WcfTest.WcfTestServiceBehavior">
            <serviceMetadata httpGetEnabled="false" httpGetUrl ="http://localhost:8080/Services/ServiceTest"/>
            <serviceDebug includeExceptionDetailInFaults="true" />
          </behavior>
        </serviceBehaviors>
      </behaviors>
    </system.serviceModel>
</configuration>
现在安装的时候都出错   求高手赐教 我的配置文件有错误吗?

解决方案 »

  1.   

    把配置文件中的
              <host>
                <baseAddresses>
                  <add baseAddress="net.tcp://localhost:9000/Services"/>
                </baseAddresses>
              </host>改为
              <host>
                <baseAddresses>
                  <add baseAddress="http://localhost:9000/Services"/>
                </baseAddresses>
              </host>
      

  2.   

    改完了还是不行   我查日志 是这样写的  
    Service cannot be started. System.InvalidOperationException: Service 'WcfService1.User' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.
      

  3.   

    同求方案,我自己试过http方式的没问题,nettcp的就不行。
      

  4.   

    请问你的app.config是在哪个项目中的?从你的命名空间看出,你有两个项目,一个是WcfTest,里面是WCF服务主体,另一个是WindowsServiceTest,里面是WCF宿主服务。显然这个错误是找不到配置文件,哪个app.config必须存在于WindowsServiceTest项目中才能找到,而你调试的时候必须在WcfTest项目中找到app.config才能保证调试正常,所以你得准备两个一模一样的app.config在两个项目中(其实也可以代码中指定那些配置参数的)。