Assiging value in VB.Net, web services

Hi Experts.  I created the service reference from the wdsl site.  The part that covers the username and password is as follows:

'''<remarks/>
    <System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1015"),  _
     System.SerializableAttribute(),  _
     System.Diagnostics.DebuggerStepThroughAttribute(),  _
     System.ComponentModel.DesignerCategoryAttribute("code"),  _
     System.Xml.Serialization.XmlTypeAttribute([Namespace]:="https://www.site.com/security")>  _
    Partial Public Class UsernameTokenType
        Inherits Object
        Implements System.ComponentModel.INotifyPropertyChanged
       
        Private usernameField As AttributedString
        Private passwordField As AttributedString
       
        '''<remarks/>
        <System.Xml.Serialization.XmlElementAttribute(Order:=0)>  _
        Public Property Username() As AttributedString
            Get
                Return Me.usernameField
            End Get
            Set
                Me.usernameField = value
                Me.RaisePropertyChanged("Username")
            End Set
        End Property

When I try and assign the username and password values using

 Dim Wsecurity As New Service1.SecurityType
 Wsecurity.Username.Value = "fred"

The compiler accepts this but I get the error

Object reference not set to an instance of an object.

Please can someone help where I'm going wrong.   Should I be assigning the username and password in the way or should I be referring to the submitted xml file where the username and password is also entered.    I also don't see how to refer the service to the applicable xml file though.

Many thanks in advance
LVL 2
PNRTAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

apeterCommented:
Username property is inside the class "UsernameTokenType" and i am not seeing that class is instantiated in your code...

Dim Wsecurity As New Service1.SecurityType
 Wsecurity.Username.Value = "fred"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PNRTAuthor Commented:
Many Thanks for your reply.   I also tried

 Dim Tkn As New ServiceReference1.UsernameTokenType
 Tkn.Username.Value = "fred"
 Tkn.Password.Value = "freda"

This also compiled but also gave me the same error
Object reference not set to an instance of an object.

I also tried

Dim x As New ServiceReference1.UsernameTokenType With {.Username  =  "fred", .Password = "freda"}

intellisense was correct but but this will not compile with the error - value of type 'String' cannot be converted to 'WindowsApplication1.ServiceReference1.AttributedString'.

Many thanks for your help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WCF

From novice to tech pro — start learning today.