如何正确设置启用Silverlight的WCF服务?

时间:2009-01-27 14:54:19

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

编辑:我开始对此问题进行结束投票,因为我解决了这个问题。我做得很好,但是我之前下载和卸载的ASP URL重写器的引用仍然在IIS中有引用。 Waclaw Stypula(带有步骤的那个)的论坛帖子帮助我意外地追踪了这个。当我启动运行命令时,IIS告诉我它(显然)找不到重写器DLL。我删除了引用,之后应用程序运行正常。


我正在按silverlight.net跟踪Jesse Liberty教程。目前我正在尝试tutorial three,但我正在“创建网络服务”标题下(大约一半)。

首先,当我通过将新服务添加到解决方案来创建新服务时,教程指示应该创建三个文件; 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.

我尝试使用Google搜索消息的不同部分,但没有找到太多有用的信息。

以下是不同文件的代码:

//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。

1 个答案:

答案 0 :(得分: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)。

相关问题