Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

handling returned data from web service

Status
Not open for further replies.

critical5

Programmer
Dec 13, 2006
37
GB
Hi I am trying to consume a third party web service....at the moment i have managed to make a connection but have a problem handling returned data....This web service returns a credit report of an applicant(address, name, and others)....any one who could help me?...I will provide further details if needed...

Thanks a lot
critical
 
What problems are you having with your data? What format's the report in?
 
Thanks for getting back to me Woogoo,

I have managed to connect to this web service and it is accepting my log on credentials but it returns no data...now the documentation from the provider states that some addresses may have more than one match(this is a credit search). Therefore when more than one match is found...an adress and name picklist is returned for the user to choose one match and this is resubmitted. Once resubmitted it should return name and address as entered(the match) as well as other components of a credit search(on a web form)

My problem is processing this picklist...i tried this code but would not work:
Code:
<%@ Page Language="VB"%>
<script runat="server">
    Protected Sub submit_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        ' We will start by creating a new proxy object which represents the creditAPI.
        ' The InitializeApiProxy function attaches the 'credentials' and 'action' headers.
        Dim apiProxy As creditAPI.creditAPI = New creditAPI.creditAPI()

        ' Create a new apicr object which will contain the details of this credit request.
        ' This will be passed by reference to the proxy object and will contain the
        ' results once the call to the API completes (unless an error occurs).
        Dim apiCR As CreditAPI.CT_apicr = New creditAPI.CT_apicr()

        Try
            ' Now that the proxy and credit request objects have been initialized,
            ' we can issue the request to the creditAPI (credit search = 5305).
            'apiProxy.Job5305(apiCR)

        Catch soapEx As Services.Protocols.SoapException
            Response.Write("An error occurred while calling the Credit API:" & Environment.NewLine & _
            soapEx.Message)
            Return

        Catch unexpectedEx As Exception
            Response.Write("An unexpected error occurred while calling the creditAPI:" & Environment.NewLine & _
            unexpectedEx.Message)
            Return

        Finally
            ' Since the proxy implements the IDisposable interface we should call its Dispose
            ' method once we're finished with it, allowing it to free its resources.
            apiProxy.Dispose()

        End Try

        ' To get this far means that the call to the API completed successfully.
        ' This would be a good point to place a breakpoint in order to examine the
        ' results using a debugger, as apiCR should have been modified by the API.
        Dim report As Page = Nothing

        Try
            If Not apiCR.creditreport Is Nothing Then
                ' Create a form to display the credit report, passing the apiCR instance to it.
                report = New Page()
                
            Else
                ' Failure to retrieve a credit report signifies that a picklist needs processing.
                Response.Write("The API was unable to exactly match the applicant at the address specified." & Environment.NewLine & _
                "Further refinement of the search criteria is possible" & Environment.NewLine )
            End If

        Finally
            ' Since the form implements the IDisposable interface we should call its Dispose
            ' method once we're finished with it, allowing it to free its resources.
            If Not report Is Nothing Then report.Dispose()

        End Try

   

        'Creates, initializes and returns a new see cref =creditAPI proxy object.

        'The 'credentials' and 'action' headers are initialized by this method.

        'Private Function InitializeApiProxy() As creditAPI.creditAPI

        ' Create a new proxy object which represents the Credit API.
        'Dim apiProxy As creditAPI.creditAPI = New creditAPI.creditAPI
        'Dim apiCR As creditAPI.CT_apicr = Me.InitializeApiRequest()
        ' We can alter the proxy URL here, if necessary.
        apiProxy.Url = "url"

        ' Create a new credentials object and attach it to the proxy object.
        Dim apiCredentials As creditAPI.CT_credentials = New CreditAPI.CT_credentials
        apiCredentials.company = "my company"
        apiCredentials.username = "username"
        apiCredentials.password = "password"
        apiProxy.credentials = apiCredentials

        ' Create a new action object and attach it to the proxy object, setting the
        ' text property to indicate the required action (credit search = 5305).
        apiProxy.action = New creditAPI.ST_action
        apiProxy.action.Text = New String() {"urn:credit.co.uk/api5/actions/5305"}

        apiProxy.Job5305(apiCR)

        'End Sub

     
        'Private Function InitializeApiRequest() As creditAPI.CT_apicr

        ' Create a new apicr object which will contain the details of this credit request.
        ' This will be passed by reference to the proxy object and will contain the
        ' results once the call to the API completes (unless an error occurs).
        'Dim apiCR As creditAPI.CT_apicr = New CreditAPI.CT_apicr

        ' Create a new credit request object and attach it to the apicr object.
        Dim apiCreditRequest As creditAPI.CT_apicreditrequest = New creditAPI.CT_apicreditrequest
        apiCreditRequest.purpose = creditAPI.ST_searchpurpose.CA
        apiCreditRequest.score = 1
        apiCreditRequest.scoreSpecified = True
        apiCreditRequest.transient = 0
        apiCreditRequest.transientSpecified = True
        apiCR.creditrequest = apiCreditRequest

        ' Create a new request applicant object and attach it to the credit request object.
        Dim apiRequestApplicant As creditAPI.CT_apirequestapplicant = New creditAPI.CT_apirequestapplicant
        apiRequestApplicant.dob = Me.txtDoB.Text
        apiRequestApplicant.dobSpecified = True
        'apiRequestApplicant.hho = Convert.ToByte(Me.chkHHO.Checked)
        apiRequestApplicant.hhoSpecified = True
        'apiRequestApplicant.tpoptout = Convert.ToByte(Me.chkTPOptout.Checked)
        apiRequestApplicant.tpoptoutSpecified = True
        apiCreditRequest.applicant = New creditAPI.CT_apirequestapplicant() {apiRequestApplicant}

        ' Create a new name object and attach it to the request applicant object.
        Dim apiName As CreditAPI.CT_name = New creditAPI.CT_name
        apiName.title = Me.txtTitle.Text
        apiName.forename = Me.txtForename.Text
        apiName.surname = Me.txtSurname.Text
        apiRequestApplicant.name = New creditAPI.CT_name() {apiName}

        ' Create a new input address object and attach it to the request applicant object.
        Dim apiInputAddress As creditAPI.CT_inputaddress = New creditAPI.CT_inputaddress
        apiInputAddress.premiseno = Me.txtPremiseNum.Text
        apiInputAddress.postcode = Me.txtPostcode.Text
        apiRequestApplicant.address = New CreditAPI.CT_inputaddress() {apiInputAddress}
        Dim cc As creditAPI.CreditAPI = New creditAPI.creditAPI()
        'Return apiCR
               
        Dim inp As creditAPI.CT_apicr = New creditAPI.CT_apicr()
        'Dim apiProxy As creditAPI.creditAPI = New creditAPI.creditAPI

        If 0 = inp.picklist.applicant(0).address(0).fullmatches.fullmatch(0).selected Then
            inp.picklist.applicant(0).address(0).fullmatches.fullmatch(0).selected = 1
            cc.credentials.password = ""
            cc.Job5305(inp) '(issue the request to the creditAPI)
        End If
        If 0 = inp.picklist.applicant(0).address(0).fullmatches.fullmatch(0).name(0).namematches.namematch(0).selected Then
            inp.picklist.applicant(0).address(0).fullmatches.fullmatch(0).name(0).namematches.namematch(0).selected = 1
            cc.credentials.password = ""
            cc.Job5305(inp)
        End If
        
    End Sub
</script>
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head>
<title>CreditAPI</title>
  </head>
<body>
<form id="Form1" runat="server" method="post" action="Default.aspx">
<table style="height: 320px; width: 256px;" id="TABLE1">
<tr>
	<td style="width: 89px">
		Title: </td>
	<td> 
		<asp:textbox id="txtTitle" runat="server"></asp:textbox>
	</td>
</tr>
<tr>
	<td style="width: 89px">
		Forename:</td>
	<td>
		<asp:textbox id="txtForename" runat="server"></asp:textbox>
	</td>
</tr>
<tr>
	<td style="width: 89px">
		Middle Names / Initials:</td>
	<td>
		<asp:textbox id="txtmiddlename" runat="server"></asp:textbox>
	</td>
</tr>
<tr>
	<td style="width: 89px">
	Surname:</td>
	<td>
		<asp:textbox id="txtSurname" runat="server"></asp:textbox>
	</td>
</tr>
<tr>
	<td style="height: 26px; width: 89px;">
		Date Of Birth:</td>
	<td style="height: 26px">
		<asp:textbox id="txtDoB" runat="server"></asp:textbox>
	</td>
</tr>
<tr>
	<td style="width: 89px">
        Opt in/Out</td>
	<td>
        &nbsp;<asp:CheckBox ID="chkHHO" runat="server" Text="HHO" />
    </td>
</tr>
<tr>
	<td style="width: 89px">
        Opt in/Out</td>
	<td>
        &nbsp;<asp:CheckBox ID="chkTPOptout" runat="server" Text="Opt In" />
        &nbsp;
        <asp:CheckBox ID="chkTPOptout1" runat="server" Text="Opt Out" /></td>
</tr>

<tr>

	<td style="width: 89px">
    Premise No:</td>
	<td>
<asp:textbox id="txtPremiseNum" runat="server"></asp:textbox>
</td>
</tr>
<tr>
	<td style="width: 89px">
    Premise Name:</td>
	<td>
<asp:textbox id="txtPremiseName" runat="server"></asp:textbox>
    </td>
</tr>
<tr>
	<td style="width: 89px">
		Postcode:</td>
	<td>
		<asp:textbox id="txtPostcode" runat="server"></asp:textbox>
	</td>
</tr>
<tr>
	<td style="width: 89px">
		Score:</td>
	<td>
	<asp:textbox id="txtScore" runat="server"></asp:textbox>
</td>
</tr>
<tr>
	<td style="width: 89px">
	Searches:</td>
	<td>
		<asp:textbox id="txtSearches" runat="server"></asp:textbox>
	</td>
</tr>


<tr>
	<td style="width: 89px">
<asp:button id="submit" runat="server" text="Submit" OnClick="submit_Click" />
	</td>
</tr>
</table>
    <br />
    <br />
    <asp:TextBox ID="txtaddress" runat="server" Height="104px" Width="264px"></asp:TextBox><br />
    </form>
   
</body>
</html>
[code]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top