none
sl无法获取到wcf的元数据,提示 ”给定关键字不在字典中。“ RRS feed

  • 问题

  • 一个WCF服务,以tcp绑定host在控制台上,客户端是console时,能够正常获取元数据且能正常调用,但是放到Silverlight中调用时出现“给定关键字不在字典中。”错误,我估计是WCF的配置文件 <serviceMetadata httpGetEnabled="false"/>这里出错,但是不知道怎么改。

    服务代码:

     

     public class Program
     {
      static void Main(string[] args)
      {
       PolicySocketServer StartPolicyServer = new PolicySocketServer();
       Thread th = new Thread(new ThreadStart(StartPolicyServer.StartSocketServer));
       th.IsBackground = true;
       th.Start();
    
       MyHost.Open();
       System.Console.WriteLine("服务已经启动... 敲任意键停止服务");
       System.Console.ReadLine();
       MyHost.Close();
      }
     }
    
     public class MyHost
     {
      static ServiceHost host = null;
      public static void Open()
      {
       host = new ServiceHost(typeof(ChatService)); 
       host.Open();
      }
      public static void Close()
      {
       if (host != null && host.State == CommunicationState.Opened)
       {
        host.Close();
       }
       host = null;
      } 
     }
     public class ChatService : IChatService
     {
      private static List<MessageInfo> listMessages = new List<MessageInfo>();
    
      public void SendMessage(MessageInfo message)
      {
       listMessages.Add(message);
      }
    
      public List<MessageInfo> GetMessages(string userName, string partnerName)
      {
       var list = listMessages.Where(m => m.PartnerName == userName && m.UserName == partnerName).ToList();
       listMessages.RemoveAll(m => m.PartnerName == userName && m.UserName == partnerName);
       return list;
      }
     }
    
     [ServiceContract]
     public interface IChatService
     {
      [OperationContract]
      void SendMessage(MessageInfo message);
    
      [OperationContract]
      List<MessageInfo> GetMessages(string userName, string partnerName);
     }
    

     

    app.config配置

     

     <system.serviceModel>
     <services>  
      <service behaviorConfiguration="Server.ChatServiceBehavior" name="Server.ChatService">
      <host>
       <baseAddresses>
       <add baseAddress="net.tcp://localhost:4503/"/>
       </baseAddresses>
      </host>
      <endpoint address="ChatService" binding="netTcpBinding" contract="Server.IChatService"></endpoint>
      <endpoint address="ChatService/mex" binding="mexTcpBinding" contract="IMetadataExchange" ></endpoint>
      </service>  
     </services> 
     
     <behaviors>
      <serviceBehaviors>
      <behavior name="Server.ChatServiceBehavior">
       <serviceMetadata httpGetEnabled="false"/>
       <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
      </serviceBehaviors>
     </behaviors>
     
     </system.serviceModel>
    

    在SL端引用的地址是net.tcp://localhost:4503/chatservice/mex,引用时没有出错,但是SL端的配置文件ServiceReferences.ClientConfig中没有数据,

    而且在运行SL时,

    ChatService.ChatServiceClient proxy = new ChatService.ChatServiceClient();

    出现“给定关键字不在字典中”的异常提示


    stay hungry stay foolish
    2010年7月18日 5:02
    版主

答案

全部回复