web service example needed in visual basic

elwin68elwin68 Member Posts: 153
edited 2009-02-24 in NAV Three Tier
Hello,

I'm new in the world of web services. I tried to get the example 'Walkthrough: Registering and Consuming a Page Web Service' from the NAV 2009 Help working.
The problem is i'm not so good in the language C. I tried to convert the example to vb but that didn't success.
I want to search for all customer within a filter and get them to vb.

The following lines must do the trick in C:
// Create filter for searching for customers
List<Customer_Filter> filterArray = new List<Customer_Filter>();
Customer_Filter nameFilter = new Customer_Filter();
nameFilter.Field = Customer_Fields.Name;
nameFilter.Criteria = "C*";
filterArray.Add(nameFilter);

Can anyone help me with an example in vb which search for the customers and get them to vb.

Thanks in advance.

Answers

  • pieter.vanparyspieter.vanparys Member Posts: 10
    this is the VB version of the code you've posted here:
    dim filterArray as New List(Of Customer_Filter)
    dim nameFilter as New Customer_Field()
    nameFilter.Field = Customer_Fields.Name
    nameFilter.Criteria = "C*"
    filterArray.Add(nameFilter)
    
  • elwin68elwin68 Member Posts: 153
    Thank you very much for the translation.
    I think something is missing in the example of the NAV help.
    The following errors occure in Visual Studio 2008:
    - Type 'Customer_Filter' is not defined
    - Name 'Customer_Fields' is not declared

    Which lines are missing in the example so the example of the web service works?

    Thanks in advance.
  • apankoapanko Member Posts: 70
    Did you add web reference to your web service?
    3. In Solution Explorer, right-click the References node in the project and select Add Web Reference.
    Note
    If you are running Visual Studio 2008, select Add Service Reference.

    4. In the Add Web Reference window, type the URL that you used when checking the WSDL, for example, http://localhost:7047/DynamicsNAV/WS/Services and then click Go.
    Note
    In Visual Studio 2008, click the Advanced button, click the Add Web Reference button, and then type the URL, and then click Go.

    5. When the Customer service is displayed, click View Service, and then click Add Reference. Rename localhost to WebService.
  • elwin68elwin68 Member Posts: 153
    Yes, In have added the web reference. When entering the link in internet explorer the service is shown.

    I have almost done the thing with the following example:

    Dim ws As New Mywebservice.Customer_Binding
    ws.UseDefaultCredentials = True
    ws.Url = "http://localhost:7047/DynamicsNAV/WS/CRONUS_International_Ltd/Page/Customer&quot;

    Dim Cust(100) As Mywebservice.Customer
    Dim wsFields As New Mywebservice.Customer_Fields
    Dim wsfilter(1) As Mywebservice.Customer_Filter
    wsfilter(1).Field = wsFields.Name
    wsfilter(1).Criteria = "J*"
    Cust = ws.ReadMultiple(wsfilter, "", 0)

    For Counter = LBound(Cust) To UBound(Cust)
    Me.ListBox1.Items.Add(Counter & ": " + Cust(Counter).No & "-> " & Cust(Counter).Name)
    Next Counter

    When leaving the 2 lines to set the filter (wsfilter(1).....), all customer appeare in the listbox.
    The only thing I want to do next is the set a filter on the field name.
    Does anyone know the syntax for that?

    Thanks in advance.
  • elwin68elwin68 Member Posts: 153
    Finally I found it myself:

    Dim ws As New Mywebservice.Customer_Binding
    ws.UseDefaultCredentials = True
    ws.Url = "http://localhost:7047/DynamicsNAV/WS/CRONUS_International_Ltd/Page/Customer&quot;

    Dim Cust(100) As Mywebservice.Customer
    Dim wsFilterArray As New List(Of Mywebservice.Klantje_Filter)
    Dim wsFilter As New Mywebservice.Klantje_Filter()
    wsFilter.Field = wsFields.Name
    wsFilter.Criteria = "C*"
    wsFilterArray.Add(wsFilter)
    Cust = ws.ReadMultiple(wsFilterArray.ToArray, "", 0)

    For Counter = LBound(Cust) To UBound(Cust)
    Me.ListBox1.Items.Add(Counter & ": " + Cust(Counter).No & "-> " & Cust(Counter).Name)
    Next Counter

    Thanks everyone for thinking with me.
Sign In or Register to comment.