无法读取vb.net Web服务中的标头信息

时间:2015-10-20 20:32:50

标签: vb.net web service asmx

我无法读取传入我的网络服务的标头。我使用curl来调用我的Web服务,它返回没有错误,但传入的标题值是空白的。

curl command with return message:
C:\curl>curl -X POST -H "Token: 123" -d '' http://localhost/Service.asm
x/GoCardLessWebHook

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://MyGoCardLessAPI.org/">200 OK - </string>

以下是Web服务代码:

Public Class clsSoapHeader
    Inherits SoapHeader
    Public Token As String
End Class



<WebService(Namespace:="http://MyGoCardLessAPI.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<System.Web.Script.Services.ScriptService()>
Public Class Service

    Inherits System.Web.Services.WebService

    Public GoCardLessHeaders As New clsSoapHeader

    <WebMethod(), _
    SoapHeader("GoCardLessHeaders", Direction:=SoapHeaderDirection.InOut)> _
    Public Function GoCardLessWebHook() As String

        Dim sTemp As String = "Unknown"

        sTemp = GoCardLessHeaders.Token


        Return "200 OK - " & sTemp

    End Function

1 个答案:

答案 0 :(得分:1)

我明白了。当我需要读取http标头时,代码正在读取soap标头。对于任何寻找答案的人来说,它非常简单。在您的Web方法中添加此代码。在这个例子中,我正在寻找标题&#39; Token&#39; :

list-style: none