Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm posting to website some valid XML.
The request works great in the SoapUI 5.4.0 environment. FileContent is good.
I'm now tying to run the event when the user clicks a button on my website.

Getting the following error back:
SOAP-ENV:Client.authenticationErrorinvalid username or password


I'm not sure if its my code or the fact I cant (don't know how to) specify the WSS-Password Type as being 'PasswordText'. Not sure it would generate this error.

Any help/suggestions/feedback would be greatly appreciated.
Thanks.

What I have tried:

VB
Protected Sub ClickButton_Test()

    Dim resultdata As String = ""
    Dim UserName As String = "Username@Location"
    Dim Password As String = "difficultpassword"

    Dim urltarget As String = "https://SpecialSite"

    Dim s As HttpWebRequest
    Dim enc As UTF8Encoding


    Dim postdatabytes As Byte()
    s = HttpWebRequest.Create(urltarget)

    enc = New System.Text.UTF8Encoding()


    Dim filecontent As String = "C:\TestData\Put_PO_XML.txt"

    Dim value As String = File.ReadAllText(filecontent)

    postdatabytes = enc.GetBytes(value)

    s.UseDefaultCredentials = False

    Dim byt As Byte() = System.Text.Encoding.UTF8.GetBytes(Password)
    Dim PasswordText As String = Convert.ToBase64String(byt)

    s.Credentials = New System.Net.NetworkCredential(UserName, PasswordText)

    s.Method = "POST"

    s.AllowAutoRedirect = True

    s.ContentType = "text/xml;charset=UTF-8"
    s.ContentLength = postdatabytes.Length
    s.KeepAlive = True
    s.ProtocolVersion = HttpVersion.Version11
    s.Host = "services.website.com"
    s.UserAgent = "Apache-HttpClient/4.1.1 (java 1.5)"

    s.AuthenticationLevel = Net.Security.AuthenticationLevel.None

    Using stream = s.GetRequestStream()
        stream.Write(postdatabytes, 0, postdatabytes.Length)
    End Using

    Try

        Dim result = s.GetResponse()

        Using stream As Stream = result.GetResponseStream()
            Dim reader As New StreamReader(stream, Encoding.UTF8)
            resultdata = reader.ReadToEnd()
        End Using
    Catch ex As WebException
        resultdata = New StreamReader(ex.Response.GetResponseStream()).ReadToEnd()

    End Try

    Me.APIResult.Text = resultdata

End Sub
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