REST WCF服务返回方法不允许

时间:2016-02-10 13:52:50

标签: c# asp.net vb.net wcf rest

这是一个WCF休息服务。我试图返回XML或json。

我已经测试并测试了它,但我得到方法不允许,我无法弄清楚我做错了什么。我跑的时候

的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" />

合同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" %>

方法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

0 个答案:

没有答案