Click here to Skip to main content
14,929,999 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
I'm trying to learn how to create a json REST webservice and starting off with a simple example ... but can't get it to function. This is what I get when attempting to call it with a cUrl ...

curl -X GET -v http://localhost:8733/Design_Time_Addresses/HelloService/HelloService/GetData/value/334
Note: Unnecessary use of -X or --request, GET is already inferred.
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8733 (#0)
> GET /Design_Time_Addresses/HelloService/HelloService/GetData/value/334 HTTP/1.1
> Host: localhost:8733
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 405 Method Not Allowed
< Allow: POST
< Content-Length: 0
< Server: Microsoft-HTTPAPI/2.0
< Date: Mon, 02 Nov 2020 21:20:50 GMT
<
* Connection #0 to host localhost left intact

C:\


If it matters I am running/serving the service using "debug mode" which calls the WCF Test Client application.

Can anyone please tell me why it thinks I should be asking for a POST?

What I have tried:

Here are my HelloService.VB, IHelloService.VB and my App.Config files:

IHelloService.vb
<ServiceContract()>
Public Interface IHelloService

    <OperationContract()>
    Function GetData(ByVal value As String) As String

End Interface


HelloService.vb
Public Class HelloService
    Implements IHelloService
    <WebInvoke(ResponseFormat:=WebMessageFormat.Json, RequestFormat:=WebMessageFormat.Json, Method:="GET", UriTemplate:="value/{value}")>
    Public Function GetData(ByVal value As String) As String Implements IHelloService.GetData
        Return String.Format("You entered: {0}", value)
    End Function


End Class



app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="HelloService.HelloService">
        <endpoint address="web" behaviorConfiguration="JsonBehavior"
          binding="webHttpBinding" contract="HelloService.IHelloService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/HelloService/HelloService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="JsonBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>
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