0

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
wolfeh
  • 666
  • 1
  • 8
  • 23
  • duplicate of http://stackoverflow.com/questions/41155/wcf-service-returning-method-not-allowed and http://stackoverflow.com/questions/13228995/wcf-error-405-method-not-allowed and http://stackoverflow.com/questions/14051246/wcf-service-returns-method-not-allowed-error –  Feb 10 '16 at 14:12
  • @Kilanny You are right I tried for 5hr yesterday searched everywhere for the answers tried every example but that one is the one that solved it. Case sensitive GET within the service contract. tks. – wolfeh Feb 10 '16 at 14:47

0 Answers0