配置文件应该生成在host下还是wcf服务下呢?我生成在host下能正常启动,但是客户端无法获取有效的引用,如果生成在wcf服务下,并设置宿主为启动首先项的时候,就会报 "通信对象 System.ServiceModel.ServiceHost 无法用于通信,因为其处于“出错”状态" 错误,请教!!我现在将配置文件app.config 生成在host下,运行成功,但是客户端无法加载服务mex 
错误信息 : 192.168.1.2 是我的IP地址
下载“http://192.168.1.2:8002/mex”时出错。
无法连接到远程服务器
由于目标机器积极拒绝,无法连接。 192.168.1.2:8002
元数据包含无法解析的引用:“http://192.168.1.2:8002/mex”。
无法连接到 http://192.168.1.2:8002/mex。TCP 错误代码 10061: 由于目标机器积极拒绝,无法连接。 192.168.1.2:8002。 
无法连接到远程服务器
由于目标机器积极拒绝,无法连接。 192.168.1.2:8002
如果该服务已在当前解决方案中定义,请尝试生成该解决方案,然后再次添加服务引用
我的配置文件信息:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1" behaviorConfiguration="WcfServiceLibrary1.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://192.168.1.2:8001/"/>
<add baseAddress="http://192.168.1.2:8002/"/>
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" contract="WcfServiceLibrary1.IWCFService"></endpoint>
<endpoint address =""binding="wsHttpBinding" contract="WcfServiceLibrary1.IWCFService"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceLibrary1.Service1Behavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

解决方案 »

  1.   

    http://www.cnblogs.com/frank_xl/archive/2009/03/25/1414686.htmlhttp://it.china-b.com/web/aspnet/20090612/84974_1.html
    http://social.microsoft.com/Forums/nl-NL/wcfzhchs/thread/f3faacba-ad4b-4a18-9c54-bf769388eeff
    第三个 网页 和你说的很相似   去看看 也许对你有用希望早日解决 呵呵
      

  2.   

    我这个不是基于web的wcf ,就是测试使用的一个wcf服务,用一个控制台程序做宿主,配置文件在wcf下生成,控制台无配置文件,控制台为启动项。调用wcf服务的时候出现的该异常,控制台启动代码 :static void Main(string[] args)
            {
                try
                {
                    using (ServiceHost host = new ServiceHost(typeof(WcfServiceLibrary1.Service1)))
                    {
                        if (host.State != CommunicationState.Opening)
                            host.Open();                    Console.WriteLine("Host is runing! and state is {0}", host.State);
                    }
                }
                catch (Exception emo)
                {
                    Console.WriteLine("ERROR: {0}", emo.Message);
                }
                Console.Read();    
               }
      

  3.   

    你就那么几句代码可以启动了?除非控制台有配置文件,否则单单那么几句代码,它不知道你用了什么协议,用了什么IP来启动,WCF下面的配置文件时给你调试用的,真正执行的时候需要放在托管程序下的,如果是控制台托管,就是控制台程序的配置文件,如果是web托管,就是web.config里。
      

  4.   


    配置文件生成在控制台宿主下的时候,是可以启动的,启动后,客户端无法获取服务引用;
    如果配置文件生成在wcf服务下,控制台启动后会出现一个【通信对象 System.ServiceModel.ServiceHost 无法用于通信,因为其处于“出错”状态】错误;
    但是该情况下,单独启动wcf服务,也可以启动,客户端也可以获取到服务的引用,
      

  5.   

    测试程序中wcf服务 接口代码:
    namespace WcfServiceLibrary1
    {
        [ServiceContract]
        public interface IWCFService
        {
            [OperationContract]
            string SayHello(string name);        [OperationContract]
            string SayHelloToUser(User user);
        }
        [DataContract]
        public struct User
        {
            [DataMember]
            public string FirstName;        public string MiddleName;//不会被传递
            [DataMember]
            public string LastName;
        }
    }
    测试程序中wcf服务接口实现代码
    namespace WcfServiceLibrary1
    {
    public class Service1 : IWCFService
        {
            public string SayHello(string name)
            {
                Console.WriteLine("Hello! {0},Using string ", name);
                return "Hello! " + name;
            }
            public string SayHelloToUser(User user)
            {
                Console.WriteLine("Hello! {0}    {1},Using DataContract ", user.FirstName, user.LastName);
                return "Hello! " + user.FirstName + " " + user.LastName;
            }
        }
    }
    /////////////////////////////////////////
    测试程序中宿主程序代码:
    namespace CAHost
    {
        class Program
        {
           try
             {
                using (ServiceHost host = new ServiceHost(typeof(WcfServiceLibrary1.Service1)))
             {
              if (host.State != CommunicationState.Opening)
              host.Open();          Console.WriteLine("Host is runing! and state is {0}", host.State);
      }
      }
      catch (Exception emo)
      {
      Console.WriteLine("ERROR: {0}", emo.Message);
      }
      Console.Read();       }
    }
      

  6.   

    先说下配置文件法:
    找到你的<services>节点,删除“<add baseAddress="net.tcp://192.168.1.2:8001/"/>”,net.tcp的地址不能作为baseAddress,同时删除<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />然后找到<endpoint address="" binding="netTcpBinding" contract="WcfServiceLibrary1.IWCFService"></endpoint>
    改为:
    <endpoint address="net.tcp://192.168.1.2:8001/" binding="netTcpBinding" contract="WcfServiceLibrary1.IWCFService"></endpoint>
    这里也可以用8002端口哦,http和net.tcp是不同的协议,用同一个端口没事。客户端要引用服务的话,必须使用http的那个地址。
    ------------------------
    以上完毕。