TMACUL

http://www.servicedeskusers.com/Web_Services.

Blog Post created by TMACUL Champion on Jan 5, 2016

From SDU

Jump to: navigation, search

To make corrections or additions to this article, select the edit tab above.
To discuss or ask questions about this article, select the discussion tab above.

 

 

Create a Request, Change Order and Contact through Web Services via VB

Step1: Create a web reference in the front end.

  1. Start the front end.
  2. Go to Website menu and click “Add web reference”.
  3. In the URL box provide the web service URL and click go. http://<hostname>:8080/axis/services/USD_R11_WebService?wsdl'''
  4. We can find the methods being pulled out.
  5. Add the webreference with the name “WebReference”.

Step 2: Create an Object of the web reference

Dim ws As New WebReference.USD_WebService

Step 3: Specify the Correct web service URL

ws.Url = "http://<hostname>:8080/axis/services/USD_R11_WebService?wsdl"

Step 4: Provide the username and password to get the sid value

Dim username, password As String Dim sid As Integer username = "analyst1" password = "123" sid = ws.login(username, password)

where login is the method used to get the sid.

Step 5: Get the User Handle

Dim userhandle As String userhandle = ws.getHandleForUserid(sid, username)

Where getHandleForUserid is the method

Step 6: Create a Request

Dim attrVal(5), attr(1), prop(1), persistent_id As String Dim requestHandle, requestNumber As String attrVal = New String() {"customer", userhandle, "category", "<category id>", "description", "Description here"} prop = New String() {""} attr = New String() {persistent_id} requestHandle = "" requestNumber = "" ws.createRequest(sid, userhandle, attrVal, prop, "", attr, requestHandle, requestNumber)

Step 7: Create a Change Order

Dim attrVal(5), attr(1), prop(1), persistent_id As String Dim requestHandle, requestNumber As String attrVal = New String() {"requestor", userhandle, "category", "category id", "description", "description here"} prop = New String() {""} attr = New String() {cpersistent_id} requestHandle = "" requestNumber = "" ws.createChangeOrder(sid, userhandle, attrVal, prop, "", cattr, requestHandle, requestNumber)

Step 8: Create a contact

Dim attrVal(5), attr(1), persistent_id As String Dim contactHandle, contactNumber As String attrVal = New String() {"first_name","Mike", "last_name", "Tolland", "userid", "mike.tolland", "contact_num", "<Password here>", "email_address", "mike.tolland@abc.co.in", "phone_number", "00989876723"} attr = New String() {persistent_id} ws.createObject(sid, "cnt", attrVal, attr, contactHandle, contactNumber)

 

Creating Code for VB.net 2008 and R11

Create object / login and return basic information

Dim sid As String Dim uHandle As String Dim b As New casoap.USD_WebServiceSoapClient sid = b.login("Administrator", "password")     Dim user As String = "devak01" uhandle = b.getHandleForUserid(sid, user) Dim arryVals As String() = {"first_name", "last_name", "organization", _ "organization.name", "admin_org.name", _ "group_list.length"} Dim arryValsresults As String = b.getObjectValues(sid, uHandle, arryVals)

 

Create a Asset / Hardware Configuration item

Dim newexten As String = "" Dim extenName As String = "" Dim assethndle As String = "" Dim car As String = "" Dim chgHandle As String = "" Dim chgNum As String = ""   Dim attrVal() As String = {"name", "hello2", "class", "grc:10000002"} ReDim Preserve attrVal(3) Dim persistent_id As String = "persistent_id" Dim attr() As String = {persistent_id} ReDim Preserve attr(0)   b.createAsset(sid, attrVal, attr, car, assethndle, newexten, extenName)

Create a Change Order

Dim attrVal() As String = {"requestor", uHandle, "category", "5103", "description", "hello world"} ReDim Preserve attrVal(5)   Dim persistent_id As String = "persistent_id" Dim attr() As String = {persistent_id} ReDim Preserve attr(0) Dim prop() As String = {} ReDim Preserve prop(1) Dim chgHandle As String = "" Dim chgNum As String = ""     b.createChangeOrder(sid, uHandle, attrVal, prop, _ "", attr, chgHandle, chgNum)

How to Use Web Services

I am using Visual Web Developer Express.Net. It is free and easy to use. To consume the USD web services, create a new web application.

Now is time to get to work

Once your page is set up:

Click the Website > add reference

Enter the URL to the web services WSDL file, which is located at' http ://< your server>:8080/axis/services/USD_R11_WebService?wsdl'

You might want to study a little XML and WSDL, but it isn't neccesary. Look up the topic, Consume or Consuming Web Services.

Quick Reference

Consuming Web service With Visual Studio/ Express Web Developer

Go to the Menu Bar and click Website > Add Web Reference (name it anything you want then click --> Add reference

And that is it!


To use the web reference, create a new instance of the web service VB.Net Class program file

Partial Class tickets Inherits System.Web.UI.UserControl   Private ws As New USD_WebService . . . To consume the service, call your first function ws.login(username, password)
'the login function returns a system id value so...' 'lets rewrite the above code to look like the code below...'   Dim sid As String sid = ws.login(username, password)

 

Example Code: Using Webservice in VB.NET Web Application

Here is a complete Code Snippit 
Imports System.IO Imports System.Xml Imports System.Xml.Serialization Imports <ReferenceToWebServiceWSDL> Imports Connection   Partial Class _Default   Inherits System.Web.UI.Page   Dim ws As New USD_WebService Dim sid As String Dim userhandle, username, password As String Dim attrVal(5), attr(0), prop(0) As String Dim requestHandle, requestNumber As String Dim persistent_id As String Dim catAttrib(5) As String   Dim xmlReturn As String Dim pcatHandle As XmlNodeList Dim xDoc As XmlDocument = New XmlDocument() Dim pcatResult As String   'Class for handling the button click submit' Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click   Dim name = “Username” Dim pass As String = "password"   sid = ws.login(name, pass)   'get the Handle for the userid' userhandle = ws.getHandleForUserid(sid,name) 'Get The Category Attributes' catAttrib = New String(0) {}   'Category Handle for the incident area' Try xReturn = ws.doSelect(sid, "pcat", "sym = 'HARDWARE.PRINTER.SETUP'", 1, catAttrib) xDoc.LoadXml(xReturn) xHandle = xDoc.GetElementsByTagName("Handle") xResult = xHandle(0).InnerText catHandle = xResult Catch ex As Exception Response.Write("Exception caught while invoking an XML Web service.") End Try   'Priority handle for the ticeket' 'sym = priority.Value' '505     0     0     None Priority unassigned' '500     0     1     5     LOW Priority '501     0     2     4     MEDIUM-LOW Priority '502     0     3     3     MEDIUM Priority '503     0     4     2     MEDIUM-HIGH Priority '504     0     5     1     HIGH Priority   Dim pri As String() pri = New String() {"pri:505", "pri:504", "pri:503", "pri:502", "pri:501", "pri:500"}   'Set the priority number Testing only' priority_number = 1     attrib = New String() {"customer", userhandle, "priority", "pri:502", "category", _ pcatResult, "description", "Test"} prop = New String() {""} attr = New String() {persistent_id} requestHandle = "" requestNumber = ""   'Create the ticket' 'Including a try catch block for catching an error dealing with additional fields' ws.createRequest(sid, userhandle, attrVal, prop, "", attr, requestHandle, requestNumber)   'I need to close the connection.' ws.logout()   End Sub   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load   ws.Url =  _ "http://<yourServerName>:8080/axis/services/USD_R11_WebService?wsdl" End Sub End Class

ASP Web Project

Create an ASP .NET Web Project Below is a sample ASP Page. Copy and paste the code Between the <Form></Form> tags.

'default.aspx' <asp:Label id="replay" runat="server" />   'Get the User Name and Password' <input type="text" id="username" runat="server" /> <input type="password" id="password" runat="server" />

I've created a demo VS 2010 ASP.NET web project to showcase a lot of functionality of the web services. Download here the project files: SD_WebService


Having Fun

Pop the code below in your VB file. When the user logs in correctly the form will disapear and s\he will be greeted by there username

'in your default.aspx.vb file' Dim ws As New USD_WebService   'Login' ws.login(username.Text, password.Text)   'Just for fun hide input areas' username.Visable = false password.Visalbe = false   'Say Hello to you user' replay.Text = " Welcome " & username.Text


If you copy and paste the code, you need to remove the aphostrophy at the end of each comment only. To do this just use your find and replace function. MenuBar Item Edit > Find and Replace --> Quck Replace > find What: ' . Next, Replace With <- test box insert a space. You'll have to do this one-by-one so not to uncomment the whole line.

create request and search request app using web services in c#

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using za.co.mtn.vmcausddv02_fld; using System.IO; using System.Xml; using System.Xml.Serialization; using System.Collections;

public partial class MAIN : System.Web.UI.Page {

   USD_WebService wsUSD = new USD_WebService(); string username = null; string password = null; int sid = 0; string userhandle = null; string[] attrVal; string[] attr; string[] prop; string persistent_id; string requestHandle; string requestNumber; string result; string login_username; string login_password; string login_userhandle; string ref_num; string res_count; string ref_handle; 
   XmlDocument Doc = new XmlDocument(); XmlNodeList nodeList = default(XmlNodeList); XmlElement root; 

 

   string xResult = null; XmlNodeList xHandle = default(XmlNodeList); XmlDocument xDoc = new XmlDocument(); 

 

protected void btnSubmit_Click(object sender, EventArgs e) { try { username = "horne_g"; password = "GavJac456"; sid = wsUSD.login(username, password); userhandle = wsUSD.getHandleForUserid(sid, username); 
           attrVal = new string[] { 

"customer", userhandle, "category", ddlCatogorie.SelectedValue, "description", txtDescription.Text

       }; prop = new string[] { "" }; attr = new string[] { "persistent_id" }; 
           requestHandle = ""; requestNumber = ""; 
           wsUSD.createRequest(sid, userhandle, attrVal, prop, "", attr, ref requestHandle, ref requestNumber); lblrequest.Text = requestNumber; // txtSearch.Text = requestNumber; //log out (sid) wsUSD.logout(sid); mtvSearchReq.Visible = true; } catch (Exception ex) { lblnumberUSDs.Text = ex.ToString(); } } 

protected void btnSearch_Click(object sender, EventArgs e)

   { username = "horne_g"; password = "GavJac456"; sid = wsUSD.login(username, password);  //ussing the array i created string[] attrs = new string[5]; attrs[2] = "ref_num"; attrs[1] = "description"; attrs[0] = "status"; attrs[3] = "group"; 
       try { sid = wsUSD.login(username, password); 
           result = wsUSD.doSelect(sid, "cr", "ref_num = '" + txtSearch.Text + "'", 2, attrs); xDoc.LoadXml(result); xHandle = xDoc.GetElementsByTagName("Attributes"); xResult = xHandle[0].InnerText;   
           ref_handle = xResult; 
           lblnumberUSDs.Text = attrs.ToString(); 
           //Doc.LoadXml(result); 
           //root = Doc.DocumentElement; //nodeList = root.SelectNodes("//Attribute[AttrName='ref_num']/AttrValue"); 

 

           //res_count = nodeList.Count.ToString(); lblnumberUSDs.Text = res_count; 
          // lblResult.Text = ref_handle; //txtresult.Text = result; txtresult.Text = ref_handle; wsUSD.logout(sid); } catch(Exception ex) { lblnumberUSDs.Text = ex.ToString(); } } 

Retrieved from "http://www.servicedeskusers.com/Web_Services"

 

 

This page was last modified 11:39, 4 October 2012.  This page has been accessed 34,259 times.  Content is available under Attribution-Noncommercial-Share Alike 3.0 UnportedDisclaimers

Outcomes