Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
I try to make Restful service using WCF VB.NET but I getting error
this is my Code:

RestService.svc:
<%@ ServiceHost Language="VB" Debug="true" Service="WOFServices.RestService" CodeBehind="RestService.svc.vb" %>




RestService.svc.vb
Imports System
Imports System.Collections.Generic
Imports System.ServiceModel
Imports System.ServiceModel.Description
Imports System.ServiceModel.Web
Imports System.Text
Imports WOFServices.WOFServices

' NOTE: You can use the "Rename" command on the context menu to change the class name "RestService" in code, svc and config file together.
Namespace RestService
    Public Class RestService
        Implements IRestService
#Region "IRestService Member"

        Public Function XmlData(id As String) As String Implements IRestService.XmlData
            Return "You Requested Product " & id
        End Function

        Public Function JsonData(id As String) As String Implements IRestService.JsonData
            Return "You Requested Product " & id
        End Function
#End Region
        Public Sub DoWork() Implements IRestService.DoWork
        End Sub

    End Class
End Namespace




IRestService.vb
Imports System
Imports System.Collections.Generic
Imports System.ServiceModel
Imports System.ServiceModel.Description
Imports System.ServiceModel.Web
Imports System.Text

' NOTE: You can use the "Rename" command on the context menu to change the interface name "IRestService" in both code and config file together.

Namespace WOFServices

    <ServiceContract()>
    Public Interface IRestService

        <OperationContract()>
            <WebInvoke(Method:="GET", ResponseFormat:=WebMessageFormat.Xml, BodyStyle:=WebMessageBodyStyle.Wrapped, UriTemplate:="xml/{id}")> _
        Function XmlData(id As String) As String


        <OperationContract()>
            <WebInvoke(Method:="GET", ResponseFormat:=WebMessageFormat.Json, BodyStyle:=WebMessageBodyStyle.Wrapped, UriTemplate:="json/{id}")> _
        Function JsonData(id As String) As String
        Sub DoWork()

    End Interface
End Namespace





Web.config
<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="WOFServices.RestService" behaviorConfiguration="ServiceBehaviour">
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address ="" binding="webHttpBinding" contract="WOFServices.IRestService" behaviorConfiguration="web">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
        </endpoint>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>




Error
Server Error in '/WOFServices' Application.

The type 'WOFServices.RestService', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The type 'WOFServices.RestService', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[InvalidOperationException: The type 'WOFServices.RestService', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.]
   System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +841
   System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +2899
   System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +66
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +1069

[ServiceActivationException: The service '/WOFServices/RestService.svc' cannot be activated due to an exception during compilation.  The exception message is: The type 'WOFServices.RestService', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found..]
   System.Runtime.AsyncResult.End(IAsyncResult result) +679246
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +420
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, String routeServiceVirtualPath, Boolean flowContext, Boolean ensureWFService) +329
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext, Boolean ensureWFService) +46
   System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +410
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225 



Iget reference this code from
Create RESTful WCF Service API: Step By Step Guide[^]
but this reference using c# language

please help me,
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900