简体   繁体   English

使用带有HTTP请求的RESTful WCF服务

[英]Use RESTful WCF Service with HTTP request

I try to consume a RESTful WCF Service by making POST requests with the DHC Plugin for Chrome . 我尝试使用DHC Plugin for Chrome发出POST请求来使用RESTful WCF服务 Unfortunately I have no idea how the JSON request should look like. 不幸的是我不知道JSON请求应该是怎样的。

The relevant parts of the VB.NET project VB.NET项目的相关部分

IUserService.vb IUserService.vb

<OperationContract(),
    WebInvoke(Method:="POST",
              UriTemplate:="/User/Create",
              RequestFormat:=WebMessageFormat.Json,
              ResponseFormat:=WebMessageFormat.Json,
              BodyStyle:=WebMessageBodyStyle.Bare)>
    Sub CreateUser(ByVal user As User)

UserService.svc.vb UserService.svc.vb

Public Sub CreateUser(ByVal user As User) Implements IUserService.CreateUser
    user.UserObject.CreateUser(user)
End Sub

User.vb User.vb

Private m_Id As Integer
Private m_Name As String
Private m_Age As Integer
Private m_Sex As Sex
Private m_Comments As String
Private Shared m_UserObj As User
Private m_LUser As List(Of User)

Public Shared ReadOnly Property UserObject() As User
    Get
        If m_UserObj Is Nothing Then
            m_UserObj = New User()
        End If

        Return m_UserObj
    End Get
End Property

Friend Sub CreateUser(ByVal user As User)
    LUser.Add(user)
End Sub

Public Enum Sex
    Male = 0
    Female = 1
End Enum

I have tried something like this without success (Response: 400 Bad request ): 我尝试过这样的事情没有成功(响应: 400 Bad request ): JSON POST请求

How should the POST request look like? POST请求应该如何?

I have just added this headers: 我刚刚添加了这个标题:

  1. Content-Type: application/json Content-Type:application / json
  2. Accept: application/json 接受:application / json

and it works like a charm 它就像一个魅力

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM