.NET C-Sharp client

The C-Sharp client project demonstrates using the Web Service Operations created by the MVS ToolKit.

C-Sharp client examples are located in the <MVS.install.dir>\samples\mv-ws-vc\ folder of your installation.

Procedure

  1. Create a Visual Studio C-Sharp solution.
  2. Right-click the references from the Solution Explorer and select the Add Web Reference option.

    The Add Web Reference dialog box displays.

  3. Enter the URL for the MV Web Service in the URL text box. In this example we have the mvs Web Service deployed on the localhost server port 8181. In this case, the URL to the WSDL document of this Web Service would be:

    http://localhost:8181/mvs?wsdl

  4. By default, Visual Studio sets the Web reference name to localhost. However, for this example, we will change the Web reference name to mvs. This is the name that will be used to reference the Web Service from the c# code.
  5. Click the Add Reference button.

    The Web Service is listed under the Web References node in the Solution Explorer.

  6. The sample application has a single form with a tab control containing five tabs hosting the web services search-inventory, check-inventory, check-inventory-by-location, list-customers and quote. To view this form, open the MVWS.cs form from the Solution Explorer.

    Note that the Service URL is displayed from the service WSDL. This can be changed here or in the associated exe.config file before starting the application.

  7. The search-inventory service runs an AQL select statement on the MVDEMO,INVENTORY, file using the DESCRIPTION ADI to select inventory items. Enter an item description and then click the Search button (in this example we enter the word OFFICE ).

    The application calls the Web Service and displays the results in the grid.

    The search-inventory service is called by the search command button event handler:

    private void btnSearch_Click(object sender, EventArgs e)
    {
       try
       {
          mvs.mvsService mvsService = new mvs.mvsService();
          mvsService.Url = txtURL.Text;
    
          mvs.searchinventory searchInventory = new mvs.searchinventory();
          searchInventory.DESC = "[" + txtDescription.Text + "]";
          mvs.searchinventoryResponse response = 
             mvsService.searchinventory(searchInventory);
          mvs.searchinventoryRow[] rows = response.searchinventoryRowSet;
          String[] gridRow = new String[6];
          dataGridSearchInventoryResults.Rows.Clear();
          foreach (mvs.searchinventoryRow row in rows)
          {
             for (int i = 0; i < row.ID.Length; i++)
             {
                gridRow[0] = row.ID[i][0];
                gridRow[1] = row.DESCRIPTION[i][0];
                gridRow[2] = row.RETAILPRICE[i][0];
                gridRow[3] = row.PROMOPRICE[i][0];
                gridRow[4] = row.QTYONHAND[i][0];
                gridRow[5] = row.TYPE[i][0];
                
             }
             dataGridSearchInventoryResults.Rows.Add(gridRow);}
          }
       }
       catch (Exception  exception)
       {
          MessageBox.Show(exception.Message, "Error accessing web services", 
          MessageBoxButton.RetryCancel, MessageBoxIcon.Error);
       }
    }
  8. The check-inventory service reads and returns an item from the MVDEMO,INVENTORY, file. Enter the Item-ID (in this example, dvd-201) and then click the Execute button.

    The item is displayed in the Response text box.

    The check-inventory service is called by the execute command button event handler:

    private void  btnExecute_Click(object sender, EventArgs e)
    {
       try
       {
          mvs.mvsService mvsService = new mvs.mvsService();
          mvsService.Url = txtURK.Text;
    
          mvs.checkinventory   checkInventory = new   mvs.checkinventory();
          checkInventory.ITEMID =  txtItemID.Text;
          mvs.checkinventoryResponse response = 
             mvsService.checkinventory(checkInventory);
          txtResponse.Text = response.ITEM;
       }
       catch (Exception  exception)
       {
          MessageBox.Show(exception.Message, "Error accessing web services", 
          MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
       }
    }
  9. The search-inventory-by-location service demonstrates calling a subroutine that takes a dynamic array of Item-ids and location codes and returns a dynamic array containing inventory information.

    The search-inventory-by-location service is called by the execute command button event handler:

    private void btnCheckInventory_Click(object sender, EventArgs e)
    {
       try
       {
          mvs.mvsService mvsService = new mvs.mvsService();
          mvsService.Url = txtURL.Text;
    
          mvs.checkinventorybylocation
             checkInventoryByLocation = new mvs.checkinventorybylocation();
    
          String [] idList = txtItemIDs.Text.Replace("\r\n", ",").Split(',');
          String [] locationList = 
             txtLocations.Text.Replace("\r\n", ",").Split(',');
          // Set the locations array
          // -----------------------
          mvs.locations[] locations = new mvs.locations[locationList.Length];
          for (int i = 0; i < locationList.Length; i++)
          {
             locations[i] = new mvs.locations();
             locations[i].locationname = locationList[i];
          }
    
          // Set the items array
          // -------------------
          mvs.items[] items = new mvs.items[idList.Length];
          for (int i = 0; i < idList.Length; i++)
          {
             items[i] = new mvs.items();
             items[i].itemid = idList[i];
             items[i].locations = locations;
          }
    
          // Create the inventory request and set it's values
          // ------------------------------------------------
          mvs.inventoryrequest request = new mvs.inventoryrequest();
          request.customerid = "123";
          request.items = items;
          checkInventoryByLocation.REQUEST = request;
          mvs.checkinventorybylocationResponse response =
          mvsService.checkinventorybylocation(checkInventoryByLocation);
          mvs.items1[] result = response.inventoryresponse.items;
          String[] gridRows = new String[10];
          dataGridSearchInventoryByLocationResults.Rows.Clear();
          for (int i = 0; i < result.Length; i++)
          {
             mvs.inventory[] inventory = result[i].inventory;
             for (int j = 0; j < inventory.Length; j++)
             {
                if (j == 0)
                {
                   gridRows[0] = result[i].itemid;
                   gridRows[1] = result[i].description;
                   gridRows[2] = result[i].listprice.ToString();
                   gridRows[3] = result[i].saleprice.ToString();
                }
                else
                {
                   gridRows[0] = ""; gridRows[1] = ""; gridRows[2] = ""; 
                      gridRows[3] = "";
                }
                gridRows[4] = inventory[j].locationid;
                gridRows[5] = inventory[j].locationname;
                gridRows[6] = inventory[j].qtyonhand.ToString();
                dataGridSearchInventoryByLocationResults.Rows.Add(gridRows);
             }
          }
       }
       catch (Exception  exception)
       {
          MessageBox.Show(exception.Message, "Error accessing web services", 
          MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
       }
    }
  10. The list-customers service lists the MVDEMO,CUSTOMERS, file by state. In this example, enter California and then click the Execute button.

    The items are displayed in the grid.

    The list-customers service is called by the execute command button event handler:

    private void cmdExecuteListCustomers Click(object sender, EventArgs e)
    }
       try
       {
          mvs.mvsService mvsService = new mvs.mvsService();
          mvsService.Url = txtURL.Text;
    
          mvs.listcustomers listcustomers = new mvs.listcustomers();
          listcustomers. STATE = txtState.Text;
          mvs.mvslistcustomersResponse response = 
             mvsService.listcustomers(listcustomers);
          mvs.mvslistcustomersRow[] rows = response.mvslistcustomersRowSet;
          String(' gridRow = new String[6];
          dataGridCustomers.Rows.Clear();
          foreach (mvs.mvslistcustomersRow row in rows) 
          {
             for (int i = 0; i < row.CUSTOMERID.Length; i++)
             {
                gridRow[0] = row.CUSTOMERID[i][0];
                gridRow[1] = row.ORGANIZATIONNAME[i][0];
                String address = row.ADDRESS[i][0] + "," +
                   row.CITY[i][0] + ", " + row.STATE[i][0] + " " + 
                      row.POSTALCODE[i][0]; 
    
                gridRow[2] = address;
                gridRow[3] = row.PHONENUMBER[i][0];
                gridRow[4] = row.CONTACTNAME[i][0];
    
             }
             dataGridCustomers.Rows.Add(gridRow);
          }
       }
       catch (Exception exception) 
       {
          MessageBox.Show(exception.Message, "Error accessing web services", 
             MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
       }
    }
  11. The quote service calls a service that retrieves the stock quote information for a given ticker symbol. In this example, enter msft and then click the Execute button. The quote information is displayed in the grid:

    The quote service is called by the execute command button event handler:

    private void btnExecuteQuote_Click(object sender, EventArgs e)
    {
       try
       {
          mvs.mvsService mvsService = new mvs.mvsService();
          mvsService.Url = txtURL.Text;
          mvs.quote quote = new mvs.quote();
          quote.SYMBOLS = txtSymbol.Text;
          mvs.mvsquoteResponse response = mvsService.quote(quote);
          dataGridQuote.Rows.Clear();
          char am = (char)254;
          String [] name = response.COMPANYNAMES.Split(am);
          String() price = response.PRICES.Split(am);
          String(' change = response.CHANGEAMTS.Split(am);
          String[' lastTrade = response.LASTTRADES.Split(am);
          String(' volume = response.VOLUMES.Split(am);
          String(' avgVolume = response.AVGVOLUMES.Split(am);
          String(' gridRow = new String[10];
          for (int i = 0; i < name.Length; i++)
          {
             gridRow[0] = name[i];
             gridRow[1] = price[i];
             gridRow[2] = change[i];
             gridRow[3] = lastTrade[i];
             gridRow[4] = volume[i];
             gridRow[5] = avgVolume[i];
             dataGridQuote.Rows.Add(gridRow);
          }
       }
       catch (Exception exception)
       {
          MessageBox.Show(exception.Message, "Error accessing web services", 
             I4essageBoxButtons.RetryCancel, MessageBoxlcon.Error);
       }
    }