InitializeWOService routine - HxGN EAM - 12.0.1 - Customization & Programming - Hexagon

HxGN EAM Web Services Toolkit Programmer

Language
English
Product
HxGN EAM
Search by Category
Customization & Programming
HxGN EAM Version
12.0.1

This routine creates an instance of the web service object (AddWorkOrderSevice) and sets all the properties that are required by the web service to create the SOAP header. The routine performs the following steps:

  • Creates an instance of the web service object and assigns it to a variable ws.

    Dim ws As New WebServices.MP0023.AddWorkOrderService

  • Attempts to read the URL for the web service from the application config file. See Application Config file. If a URL is defined in the config file, it will be used to override the default by setting the URL property of ws to the new value. If not overridden, the web service classes created from the WSDL file will point to the default URL of the HxGN web services, usually localhost.

    ' Read the URL for the web services from the app config file

    Dim url As String = AppSettings.Get(WEBSERVICES_URL_SETTINGS_KEY)

Else

If Not url Is Nothing AndAlso url.Length > 0 Then url = url.Trim()

' May throw System.UriFormatException if url is invalid If url.Length > 0 Then ws.Url = url

' if the URL is not defined in the app config file, ' the web service will attempt to use the default

' URL defined by the WSDL file

End if

  • Sets the OrganizationValue property of ws. The type of this property is Organization, which is a class that was created from the WSDL file. Since it is a class, it must first be instantiated,

    ws.OrganizationValue = New WebServices.MP0023.Organization

    and then its properties must be set. The Organization class has one property named Text that takes an array of organization strings.

    ws.OrganizationValue.Text = New String() {org}

  • Creates a UserNameToken xml element that holds the username and password as elements and stores in the token variable.

    Dim token As XmlElement = New

    XmlDocument().CreateElement("UserNameToken ") Dim node As XmlNode

    token.SetAttribute("Id", "MyId")

    node = token.OwnerDocument.CreateElement("Username")

    node.InnerText = username token.AppendChild(node)

    node = token.OwnerDocument.CreateElement("Password")

    node.InnerText = password token.AppendChild(node)

    The element is defined in the secext.xsd schema file and looks like the following:

    <UserNameToken Id="MyID" xmlns="">

    <Username>user</Username>

    <Password>password</Password>

    </UserNameToken>

    If we had been working with a previously established session, we would have created a Session element instead. See the Web Services Toolkit User's Guide.

  • Assigns the created UserNameToken element to the SecurityValue property of ws. The type of this property is Security, which is a class that was created from the WSDL file. Since it is a class, it must first be instantiated,

    ws.SecurityValue = New WebServices.MP0023.Security

    and then its properties must be set. The SecurityValue class has one property named Text that takes an array of strings.

    ws.SecurityValue.Any = New XmlElement() {token}

  • Sets the SessionScenarioValue property of ws. The type of this property is SessionScenario, which is a class that was created from the WSDL file. Since it is a class, it must first be instantiated,

    ws.SessionScenarioValue = New WebServices.MP0023.SessionScenario

    and then its properties must be set. The SessionScenario class has one property named Text that takes an array of strings.

    ws.SessionScenarioValue.Text = New String() {"terminate"}

    The terminate text tells the web service not to establish a session to be maintained between web service calls. See the Web Services Toolkit User's Guide.

  • Returns the created instance.