Consuming Web Services - Issue with forming request (ASP.NET Client - VB)

This is my first attempt at using web services through .NET and need some guidance so please pardon my ignorance on the subject.

I'm using VS 2008, VB, SOAP based Web Service and my project is setup as a web site. The Web Service is provided by a third party and is hosted elsewhere. So far, I've been able to 'Add Web Reference' and also created a proxy class using the WSDL.exe tool with the hope that I'd understand how to exchange my requests by looking at the methods/classes defined in the proxy class.

I am having fundamental issues with forming a valid request. The vendor has asked me to send a request by supplying a value to filter the data by. This means sending my company id and the id of the person I'm requesting information on as the filter in my request. I'm having problems with creating this sort of filter. I thought it would be as simple as passing a couple of parameters to a method but these two filters are set as custom types/objects.

I'm not exactly sure how to formulate the code to send the two keys as part of my xml request payload. Below I'm posting the XML request payload as it's required by the third party service, a few classes from my proxy file (that I believe are most relevant), and what I've got so far in my .aspx.vb file.

Any help, guidance or code examples will be greatly appreciated. Please let me know if I need to post additional information/code.
=======
proxy class (shortened for purpose) 
=======

<System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038"),  _
 System.SerializableAttribute(),  _
 System.Diagnostics.DebuggerStepThroughAttribute(),  _
 System.ComponentModel.DesignerCategoryAttribute("code"),  _
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true)>  _
Partial Public Class GetEmployeePersonalInfoRequestFilter
    
    Private employeesField() As EmployeeKeyType
    
    Private companiesField() As String
    
    Private lastNamesField() As EmployeeLastNameKeyType
    
    '''<remarks/>
    <System.Xml.Serialization.XmlArrayItemAttribute("EmployeeKey", Form:=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable:=false)>  _
    Public Property Employees() As EmployeeKeyType()
        Get
            Return Me.employeesField
        End Get
        Set
            Me.employeesField = value
        End Set
    End Property
    
    '''<remarks/>
    <System.Xml.Serialization.XmlArrayItemAttribute("CompanyIdentifier", Form:=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable:=false)>  _
    Public Property Companies() As String()
        Get
            Return Me.companiesField
        End Get
        Set
            Me.companiesField = value
        End Set
    End Property
    
    '''<remarks/>
    <System.Xml.Serialization.XmlArrayItemAttribute("LastNameKey", Form:=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable:=false)>  _
    Public Property LastNames() As EmployeeLastNameKeyType()
        Get
            Return Me.lastNamesField
        End Get
        Set
            Me.lastNamesField = value
        End Set
    End Property
End Class

<System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038"),  _
 System.SerializableAttribute(),  _
 System.Diagnostics.DebuggerStepThroughAttribute(),  _
 System.ComponentModel.DesignerCategoryAttribute("code")>  _
Partial Public Class EmployeeKeyType
    
    Private identifierField As EmployeeKeyTypeIdentifier
    
    Private companyIdentifierField As String
    
    '''<remarks/>
    <System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>  _
    Public Property Identifier() As EmployeeKeyTypeIdentifier
        Get
            Return Me.identifierField
        End Get
        Set
            Me.identifierField = value
        End Set
    End Property
    
    '''<remarks/>
    <System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>  _
    Public Property CompanyIdentifier() As String
        Get
            Return Me.companyIdentifierField
        End Get
        Set
            Me.companyIdentifierField = value
        End Set
    End Property
End Class

'''<remarks/>
<System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038"),  _
 System.SerializableAttribute(),  _
 System.Diagnostics.DebuggerStepThroughAttribute(),  _
 System.ComponentModel.DesignerCategoryAttribute("code"),  _
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true)>  _
Partial Public Class EmployeeKeyTypeIdentifier
    
    Private nationalIdField As NationalIdType
    
    Private employeeIdField As String
    
    '''<remarks/>
    <System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>  _
    Public Property NationalId() As NationalIdType
        Get
            Return Me.nationalIdField
        End Get
        Set
            Me.nationalIdField = value
        End Set
    End Property
    
    '''<remarks/>
    <System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>  _
    Public Property EmployeeId() As String
        Get
            Return Me.employeeIdField
        End Get
        Set
            Me.employeeIdField = value
        End Set
    End Property
End Class

'''<remarks/>
<System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038"),  _
 System.SerializableAttribute(),  _
 System.Diagnostics.DebuggerStepThroughAttribute(),  _
 System.ComponentModel.DesignerCategoryAttribute("code")>  _
Partial Public Class NationalIdType
    
    Private idOwnerField As NationalIdOwnerType
    
    Private valueField As String
    
    '''<remarks/>
    <System.Xml.Serialization.XmlAttributeAttribute()>  _
    Public Property idOwner() As NationalIdOwnerType
        Get
            Return Me.idOwnerField
        End Get
        Set
            Me.idOwnerField = value
        End Set
    End Property
    
    '''<remarks/>
    <System.Xml.Serialization.XmlTextAttribute()>  _
    Public Property Value() As String
        Get
            Return Me.valueField
        End Get
        Set
            Me.valueField = value
        End Set
    End Property
End Class



===========
Sample XML Request Payload
===========

<GetEmployeePersonalInfoRequest>
  <Filter>
    <Employees>
      <EmployeeKey>
        <Identifier>
          <NationalId idOwner="US">111-11-1111</NationalId>
        </Identifier>
        <CompanyIdentifier>test.com</CompanyIdentifier>
      </EmployeeKey>
    </Employees>
  </Filter>
</GetEmployeePersonalInfoRequest>


===========
.aspx.vb
===========

    Protected Sub GetMyPersonalInfo()

        Dim oGetPersonalInfoService As GetEmployeePersonalInfoService = New GetEmployeePersonalInfoService()

        Dim oUsernameToken As New UsernameToken(USERNAME, SECRET)
        Dim oSecurityHeaderXml As System.Xml.XmlElement = oUsernameToken.GetXml(New System.Xml.XmlDocument())
        Dim oSecurityHeader As New SecurityHeaderType()
        oSecurityHeader.Any = New System.Xml.XmlElement() {oSecurityHeaderXml}
        oGetPersonalInfoService.Security = oSecurityHeader

        Dim oFilter As New GetEmployeePersonalInfoRequestFilter()
       

    End Sub

Open in new window

sk1922Asked:
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.

Alfred A.Commented:
Hi,

What are the data types of these two filters?  Have you reviewed the web service provider website for instructions?  Normally, in an .asmx site, it should provide details on how to do it using SOAP 1.1 or 1.2 by clicking on the expose webmethod.

Also, in order for us to avoid dealing with non-primitive parameters (objects), we use XML data as string for request and response.
0
sk1922Author Commented:
Hi Alfred1,
thank you for responding. The web service is not an asmx... They gave me wsdl addresses... When I add the web ref. it give me the XML

I have used the instructions from the provider site but it provides a very basic example which returns all data... I'm trying to filter it to return only one complete record at a time.

The filter types are strings but I have to instantiate several objects in order to set them... In my code above the proxy class section shows that... They're a nested a couple of partial classes deep and having problems instantiating these objects in the correct order to set the values then set it to filter. I hope that makes sense. I'm going to post some code Ive been messing with in just a few
0
sk1922Author Commented:
here's the code that I've been messing and trying to form a correct filter request.

using their example, I can return all records by company id by setting this:

        Dim oFilter As New GetEmployeePersonalInfoRequestFilter()
        oFilter.Companies = New String() {COMPANY_IDENTIFIER}
        oFilter.Employees = <!------------------ DON'T KNOW HOW TO SET THIS TO THE NationalIdType/NationalId Value of String

        Dim oRequest As New GetEmployeePersonalInfoRequest()
        oRequest.Filter = oFilter

But that's fairly simple since in my proxy class (above) the Partial Class GetEmployeePersonalInfoRequestFilter exposes the "Companies" public property as a String, whereas "Employees" is exposed as "EmployeeKeyType" and the "EmployeeKeyType" Class exposes "Identifier" and so on.

        Dim myInfo As New GetEmployeePersonalInfoService()

        Dim oSecurityHeaderXml As System.Xml.XmlElement = oUserNameToken.GetXml(New System.Xml.XmlDocument())
        Dim oSecurityHeader As New SecurityHeaderType()
        oSecurityHeader.Any = New System.Xml.XmlElement() {oSecurityHeaderXml}
        myInfo.Security = oSecurityHeader

        Dim ekeyType As New EmployeeKeyType()
        ekeyType.Identifier = New EmployeeKeyTypeIdentifier()

        Dim ssn As New NationalIdType()
        ssn.Value = "111-11-1111"

        Dim ekeyID As New EmployeeKeyTypeIdentifier()
        ekeyID.NationalId = New NationalIdType()

        Dim reqFltr As New GetEmployeePersonalInfoRequestFilter()
        reqFltr.Employees = New EmployeeKeyType() {ekeyType}

        Dim oRequest As New GetEmployeePersonalInfoRequest()
        oRequest.Filter = reqFltr

        Dim ArrPersonInfo As EmployeePersonalInfoType() = myInfo.GetEmployeePersonalInfo(oRequest)

        For i As Integer = 0 To ArrPersonInfo.Length - 1
            Dim strLName As String = ArrPersonInfo(i).PersonalInfo.PersonName.LastName
            Response.Write(strLName)
        Next

Open in new window

0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

sk1922Author Commented:
that code block above is what I've been messing with trying form a request filter.
0
Alfred A.Commented:
Would that be

<Employees>
    <NationalIdType>Staff</NationalIdType>
    <NationalId>100</NationalId>
</Employees>
0
Alfred A.Commented:
Oh I think I got it based on your proxy class

<Employees>
       <nationalId idOwner=""> </nationalId>
       <employeeId></employeeId>
</Employees>
0
Alfred A.Commented:
Hi,

I didn't see that you have your XML request payload in the post.

What error are you exactly getting by the way?
0
Alfred A.Commented:
Hi

Check this out to get an idea, I hope it helps.  Try to do this in a hierarchical way from Employees and then going down to the child tags.


        Dim ekeyType As New EmployeeKeyType()
        ekeyType.employeeId = New EmployeeKeyTypeIdentifier()

        Dim ssn As New NationalIdType()
        ssn.Value = "111-11-1111"

        ekeyType.nationalId.idOwner = ssn.Value

        ekeyType.employeeId = "whatever is this value"

        Dim reqFltr As New GetEmployeePersonalInfoRequestFilter()
        reqFltr.Employees = New EmployeeKeyType() {ekeyType}

Open in new window

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
sk1922Author Commented:
In my initial post I threw in an example of the XML Payload (as provided by the provider in their example), it was kind of buried though.

Posted here:
===========
Sample XML Request Payload
===========

<GetEmployeePersonalInfoRequest>
  <Filter>
    <Employees>
      <EmployeeKey>
        <Identifier>
          <NationalId idOwner="US">111-11-1111</NationalId>
        </Identifier>
        <CompanyIdentifier>test.com</CompanyIdentifier>
      </EmployeeKey>
    </Employees>
  </Filter>
</GetEmployeePersonalInfoRequest>

Open in new window

0
CodeCruiserCommented:
You need to pass objects of custom classes as parameters. Here is an example of using custom classes with webservices

http://www.codeproject.com/KB/webservices/leaditwebservicewrapper.aspx

0
sk1922Author Commented:
So, I tried the hierarchical approach mentioned by Alfred1 and go it to work!

CodeCruiser, thank you very much for the post - wish I would have seen this a long time ago.

I'm posting my end result below

Dim natID As New NationalIdType()
        natID.Value = ssn
        natID.idOwner = NationalIdOwnerType.US

        Dim oEmpKey As EmployeeKeyType = New EmployeeKeyType()
        oEmpKey.Identifier = New EmployeeKeyTypeIdentifier()
        oEmpKey.Identifier.NationalId = natID
        oEmpKey.CompanyIdentifier = "xxx.com"

        Dim oFilter As New GetEmployeePersonalInfoRequestFilter()
        oFilter.Employees = New EmployeeKeyType() {oEmpKey}
        oFilter.Companies = New String() {CO_ID}

        Dim oPersonalInfoRequest As New GetEmployeePersonalInfoRequest()
        oPersonalInfoRequest.Filter = oFilter

        Dim empInfo As EmployeePersonalInfoType() = oGetPersonalInfoService.GetEmployeePersonalInfo(oPersonalInfoRequest)

Open in new window

0
sk1922Author Commented:
I am splitting points based on what I felt was most useful, in my case. The link was helpful so didn't want to deny CodeCruiser of points on this. Seems like a fair split.
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
Web Languages and Standards

From novice to tech pro — start learning today.