Link to home
Start Free TrialLog in
Avatar of sk1922
sk1922

asked on

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

Avatar of Alfred A.
Alfred A.
Flag of Australia image

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.
Avatar of sk1922
sk1922

ASKER

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
Avatar of sk1922

ASKER

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

Avatar of sk1922

ASKER

that code block above is what I've been messing with trying form a request filter.
Would that be

<Employees>
    <NationalIdType>Staff</NationalIdType>
    <NationalId>100</NationalId>
</Employees>
Oh I think I got it based on your proxy class

<Employees>
       <nationalId idOwner=""> </nationalId>
       <employeeId></employeeId>
</Employees>
Hi,

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

What error are you exactly getting by the way?
ASKER CERTIFIED SOLUTION
Avatar of Alfred A.
Alfred A.
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sk1922

ASKER

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

SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sk1922

ASKER

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

Avatar of sk1922

ASKER

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.