我试图创建我的第一个WCF宁静服务。 我在读这页:http://www.colossaltechnologies.com/vd/index.php?option=com_content&view=article&id=128%3Awcf-rest-example&Itemid=101 并试图复制代码。WCF服务。启动主机并获取正确的URI
但是,我没有我的WCF服务在一个单独的应用程序,但将其添加到我现有的Web应用程序项目。 该服务将不在我目前的项目范围之外。我想要实现的是,这种剩余服务可以从需要开发的移动应用程序(iOS/Android/Windows Phone)中调用。
我注意到,在上面的教程这一步:“创建服务主机” 现在,我想知道的是:你真的需要运行代码来启动主机,如果是这样:何时以及如何做我在生产服务器上运行它?
看来我确实需要对那个主机做些什么开始,因为现在当我去了:www.test.com/api/job/bob(我也试过了www.test.com/job/bob) 。 我得到了404个。
在我的代码下面,我希望任何人都能看到我做错了什么。我没有使用正确的URI吗?我错过了什么?
Iweddingservice.vb
Imports System.ServiceModel
Imports System.Web
Imports System.IO
Imports System.Runtime.Remoting.Activation
Imports System.Collections.Generic
Namespace RestService
<ServiceContract()>
Public Interface Iweddingservice
<OperationContract()> _
<Web.WebGet(UriTemplate:="job/{name}")> _
Function DoJob(name As String) As String
End Interface
End Namespace
** ** weddingservice.svc.vb
Imports System.ServiceModel
Imports System.ServiceModel.Web
Imports System.IO
Imports System.ServiceModel.Activation
Imports System.Web.Script.Serialization
Imports System.Collections.Generic
Imports System.Xml
Imports System.Net
Namespace RestService
Public Class weddingservice
Implements Iweddingservice
Public Function DoJob(name As String) As String Implements Iweddingservice.DoJob
Return String.Format("Hello, {0}", name)
End Function
End Class
End Namespace
** **的web.config
<rewrite>
<rules>
<rule name="api access 2">
<match url="^api/job/$" />
<action type="Rewrite" url="weddingservice.svc/api/job/" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<system.serviceModel>
<services>
<service name="RestService.weddingservice">
<host>
<baseAddresses>
<add baseAddress="http://www.test.com/api"/>
</baseAddresses>
</host>
<endpoint binding="webHttpBinding" contract="RestService.Iweddingservice" />
</service>
</services>
</system.serviceModel>
@Floran,如果你看到你的svc文件的标记,那么它将具有属性'service =“TopTrouwen.weddingservice”'。此类名称必须与您的代码隐藏类中的类名匹配。根据您发布的代码,该属性应该读取“service =”RestService.weddingservice“'。当然,确保你没有任何错误地构建你的项目! – VinayC 2012-02-28 04:54:06
即使svc文件的标记显然不正确,就像您提到的那样,我的项目无错地生成了!现在标记为:<%@ ServiceHost Language =“VB”Debug =“true”Service =“RestService.weddingservice”CodeBehind =“weddingservice.svc.vb”%> 我现在得到:类型'RestService.WeddingService',作为ServiceHost指令中的Service属性值提供,或者在配置元素system.serviceModel/serviceHostingEnvironment/serviceActivations中提供。 我能做什么? – Flo 2012-02-28 09:05:43
@Floran,请查看案例 - 是RestService.WeddingService还是RestService.weddingService?该错误仅表明.NET无法找到名为RestService.WeddingService的类型。 – VinayC 2012-02-28 09:24:14