【问题标题】:How do I properly set up a Silverlight-Enabled WCF Service?如何正确设置启用 Silverlight 的 WCF 服务?
【发布时间】:2010-10-03 18:41:33
【问题描述】:

编辑:我开始对这个问题进行非公开投票,因为我解决了这个问题。我做的一切都很好,但是对我不久前下载和卸载的 ASP URL 重写器的引用在 IIS 中仍然有引用。 Waclaw Stypula(有步骤的那个)的这个论坛帖子帮助我偶然发现了这个问题。当我启动运行命令时,IIS 告诉我它(显然)找不到重写器 DLL。我删除了引用,之后应用程序运行良好。


我正在关注 Jesse Libertysilverlight.net 教程。目前我正在尝试做tutorial three,但我在标题“CREATE THE WEB SERVICE”下碰到了一面墙(大约一半)。

首先,当我通过将新服务添加到解决方案中来创建新服务时,教程指出应该创建三个文件; IService1.vbService1.svcService1.svc.vb。将服务添加到解决方案时,我没有得到 IService1.vb 文件。我downloaded他们提供的项目的副本,Service1.svc.vb文件在里面,所以我手动添加了一个并复制了文件的内容。该教程说它是一个 VB 教程,但在随附的屏幕截图中 displays C# 所以也许这就是问题所在。

像教程一样完成所有文件后(复制/粘贴以确保没有错字),我尝试添加服务引用并收到以下错误:

The service class of type KeyboardControl_Web.Service1 both defines a ServiceContract and inherits a ServiceContract from type KeyboardControl_Web.IService1. Contract inheritance can only be used among interface types. If a class is marked with ServiceContractAttribute, it must be the only type in the hierarchy with ServiceContractAttribute. Consider moving the ServiceContractAttribute on type KeyboardControl_Web.IService1 to a separate interface that type KeyboardControl_Web.IService1 implements.

我尝试用谷歌搜索邮件的不同部分,但没有找到太多有用的信息。

这是不同文件的代码:

//IService1.vb
Imports System.ServiceModel

' NOTE: If you change the class name "IService1" here, you must also update
'       the reference to "IService1" in Web.config.
<ServiceContract()> _
Public Interface IService1

    <OperationContract()> _
   Function GetAllLocations() As List(Of Address)

End Interface

//Service1.svc.vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Runtime.Serialization
Imports System.ServiceModel
Imports System.Text

' NOTE: If you change the class name "Service1" here, you must also
'       update the reference to "Service1" in Web.config and in the
'       associated .svc file.

Public Class Service1
    Implements IService1
    Public Function GetAllLocations() As List(Of Address) Implements IService1.GetAllLocations
        Dim db As New DataClasses1DataContext()
        Dim matchingCustomers = From cust In db.userControlDemos Select cust
        'Return matchingCustomers.ToList()
    End Function
End Class

我是 Silverlight/WCF 以及接口和服务的新手。你们能帮我走上正轨吗?

编辑:我应该补充一点,我在 Windows Vista Business SP1 上使用 Visual Studio 2008。

【问题讨论】:

    标签: vb.net silverlight wcf web-services interface


    【解决方案1】:

    如果您安装了适用于 Visual Studio 的 Silverlight 工具,而不是使用默认的 WCF 模板,请考虑使用“启用 Silverlight 的 WCF 服务”,它可以为您简化事情并放置所有必需的配置。这个新模板是在 Beta 2 中引入的,并且仍然存在(参考:http://timheuer.com/blog/archive/2008/06/06/changes-to-accessing-services-in-silverlight-2-beta-2.aspx)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-26
      • 1970-01-01
      • 1970-01-01
      • 2011-10-13
      相关资源
      最近更新 更多