This is a WCF Rest Service. I am trying to return either XML or json.
I've tested and tested it but I get Method Not allowed and I can't figure out what I am doing wrong. When I run it
web.config
<system.serviceModel>
<services >
<service name="Project.TestService" behaviorConfiguration="TestServiceBehavior">
<endpoint
address=""
binding="webHttpBinding"
contract="Project.ITestService"
behaviorConfiguration="web">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="TestServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
Contract ITestService.vb
Imports System.ServiceModel
Imports System.ServiceModel.Web
<ServiceContract()>
Public Interface ITestService
<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
End Interface
SVC Markup TestService.svc
<%@ ServiceHost Language="VB" Debug="true" Service="Project.TestService" CodeBehind="TestService.svc.vb" %>
Method TestService.svc.vb
Imports Project.MODEL
Imports System.ServiceModel.Activation
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Required)> _
Public Class TestService
Implements ITestService
Public Function XMLData(id As String) As String Implements ITestService.XMLData
Return "Your request product " + id
End Function
Public Function JSONData(id As String) As String Implements ITestService.JSONData
Return "Your request product " + id
End Function
End Class
URL
http://localhost:23390/TestService.svc/xml/ABC