日期:2014-05-20  浏览次数:20782 次

WCF直接通过绑定进行通信不成功,求助各位大虾
初学WCF。晚上按书练习直接绑定进行通信内容时不成功,没找到原因,请教名位大虾。。。
始终报:TCP error code 10061: 由于目标机器积极拒绝,无法连接。 127.0.0.1:80.
防火墙已经关掉了。问题依旧.泪奔。。。。
代码如下:
lister工程:

namespace Lister
{
  class Program
  {
  static void Main(string[] args)
  {
  Uri lister = new Uri("http://127.0.0.1:9999/lister");
  Binding binding = new BasicHttpBinding();
  IChannelListener<IReplyChannel> channelListener = binding.BuildChannelListener<IReplyChannel>(lister);
  channelListener.Open();

  IReplyChannel channel = channelListener.AcceptChannel(TimeSpan.MaxValue);

  channel.Open();
  Console.WriteLine("start lister...");

  while (true)
  {
  try
  {
  RequestContext request = channel.ReceiveRequest(TimeSpan.MaxValue);
  Console.WriteLine("接收到请求消息:\n{0}", request.RequestMessage);

  request.Reply(CreateReplyMessage(binding));
  }
  catch (Exception ex)
  { 
   
  }
  }
  }

  static Message CreateReplyMessage(Binding binding)
  {
  String action = "urn:artech.com/reply";
  String body = "this is a simple message for reply";

  return Message.CreateMessage(binding.MessageVersion, action, body);
  }
  }
}

Sender工程:
namespace Sender
{
  class Program
  {
  static void Main(string[] args)
  {
  Uri uri = new Uri("http://127.0.0.1/9999/lister");
  Binding binding = new BasicHttpBinding();

  IChannelFactory<IRequestChannel> channelFactory = binding.BuildChannelFactory<IRequestChannel>();

  channelFactory.Open();

  IRequestChannel channel = channelFactory.CreateChannel(new EndpointAddress(uri));
  channel.Open();

  Message replyMessage = channel.Request(CreateRequestMessage(binding));
   
  Console.WriteLine("接收到回复消息;\n{0}",replyMessage);

  Console.ReadLine();

  }

  static Message CreateRequestMessage(Binding binding)
  {
  string action = "urn:artech.com/request";
  string body = "this is a simple request messsage";

  return Message.CreateMessage(binding.MessageVersion, action, body);
  }
  }
}
跪求各位大虾支支招。谢谢。

------解决方案--------------------
你把 : 号 打成 / 号了。