• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 629
  • Last Modified:

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:

    <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
        <System.Xml.Serialization.XmlElementAttribute(Order:=0)>  _
        Public Property Username() As AttributedString
                Return Me.usernameField
            End Get
                Me.usernameField = value
            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
1 Solution
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"
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now