IIS中的WCF / Silverlight回调服务器失败

时间:2009-09-15 15:14:58

标签: wcf silverlight

使用Silverlight 3,Windows XP,IIS 5.1,我编写了一个小应用程序,它根据MSFT文章使用调用服务器的通道方法而不是“添加服务引用”。

当使用地址localhost和端口号在VS 2008中的开发计算机上运行应用程序时,应用程序将打开并且对服务器的调用有效。当我将地址更改为计算机名称dellnov2006并将应用程序发布到IIS时,应用程序将打开,但是对Web服务的调用不起作用。

在Web Dev Helper中观看该调用,我发现该应用正在尝试调用服务文件http://dellnov2006/Service1.svc,并且收到404错误。

到目前为止,我已经:

- 在IIS中将.svc类型映射到aspnet-isapi.dll - 运行实用程序CleanIISScriptMaps -Run aspnet_regiis.exe -i -enable

任何帮助都会受到赞赏 - 我对这个想法已经不多了。

-

这是对服务器的回调,以及Service1.svc文件的内容:

 private void Button_Click(object sender, RoutedEventArgs e)
    {
      // create a custom binding that uses HTTP and binary encoding
      var elements = new List<BindingElement>();
      elements.Add(new BinaryMessageEncodingBindingElement());
      elements.Add(new HttpTransportBindingElement());
      var binding = new CustomBinding(elements);

      // create a channel factory for the service endpoint configured
      //   with custom binding

      //var cf = new ChannelFactory<IService1>(binding,
      //   new EndpointAddress("http://localhost:1042/Service1.svc"));

      var cf = new ChannelFactory<IService1>(binding,
         new EndpointAddress("http://dellnov2006/Service1.svc"));

      // save the syncronized context for the ui thread
      uiThead = SynchronizationContext.Current;

      // open the channel
      IService1 channel = cf.CreateChannel();

      // invoke the method asychrnoously
      channel.BeginGetPerson(4, GetPersonCallback, channel);
    }

以下是svc文件的内容:

<%@ ServiceHost Language="C#" Debug="true" Service="SilverlightChannelApp1.Web.Service1" CodeBehind="Service1.svc.cs" %>

非常感谢 迈克托马斯

3 个答案:

答案 0 :(得分:0)

可以是以下之一:

  • 服务的web.config存在问题。例如,localhost是地址的一部分。
  • 服务找不到应该在bin目录中的dll

尝试使用网络浏览器浏览服务

答案 1 :(得分:0)

尝试将端口号添加到计算机名称。每当我通过虚拟机测试本地站点时,这对我来说都是必需的。

改变这个:

new EndpointAddress("http://dellnov2006/Service1.svc"));

对此:

new EndpointAddress("http://dellnov2006:1042/Service1.svc"));

答案 2 :(得分:0)

对此的解决方案非常简单,但我想到了你的两个答案 它

按照Shiraz的建议浏览服务,因此调用服务时出现问题。

建议更改端点地址以包含端口#听起来不错,但没有用。

解决方案是改变:

new EndpointAddress("http://dellnov2006/Service1.svc"));

到此:

new EndpointAddress("http://dellnov2006/Silverlight/Service1.svc"));

其中'Silverlight'是虚拟目录的别名。换句话说,我在IIS上打开应用程序为“http://dellnov2006/Silverlight/

非常感谢,我无法相信经过这么多时间花在寻找之上是多么简单。我一个人工作,如果不是这个论坛,我会遇到严重麻烦。 迈克托马斯