CA service desk web service visual basic experts - asp.net

I'm working on a form that uses CA service desk web service request system, but am having trouble finding any assistance or coding examples for the service with asp.net and visual basic. I contacted their technical support, but no one on their staff has experience using it. Do you know where I could get help?

Just finished doing a vb.net webservice to CA service desk. Hopefully some of the code below can be used in your project.
Imports System.Xml
Imports Microsoft.Web.Services3
Imports Microsoft.Web.Services3.Messaging
Imports Microsoft.Web.Services3.Addressing
Partial Class _Default
Inherits System.Web.UI.Page
Dim ws1 As New USD_WebService.USD_WebService
Public sid As Integer
Public userhandle, username, password As String
Public summary, description, incident, MH, SUN As String
Public group, category, uammsg, handle As String
Dim attrVal(5), attr(1), prop(1) As String
Public requestHandle, requestNumber As String
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
ws1.Url = "http://"YOUR SERVER":8080/axis/services/USD_R11_WebService?wsdl"
'Get the Field values for the ticket (Could be done connecting to LDAP server)
username = userid1.Value 'Name from form field
password = pass1.Value 'Windows Password from form field
summary = Summary1.Value 'Summary from form field
description = desc1.Value 'Description from form field
'Get the SID from the CA Server
sid = ws1.login(username, password)
If (sid <= 0) Then
Response.Write("login failed")
Else
Response.Write("login succeeded")
End If
'Get the User ID from the CA Server
userhandle = ws1.getHandleForUserid(sid, username)
'Set the Field values to create the ticket.
'The AttrVal must be in pairs or the call will fail
'e.g. header & header details
attrVal = New String() {"customer", userhandle, "category", category, "group", group, "description", description, "summary", summary, "ZReporting_Method", "400001", "impact", "5", "type", "R"}
prop = New String() {""}
attr = New String() {"persistent_id"}
'Returned data from the CA server
requestHandle = ""
requestNumber = ""
'Send the request with the details from the form
ws1.createRequest(sid, userhandle, attrVal, prop, "", attr, requestHandle, requestNumber)
Response.Write("Ticket Number: " + requestNumber + " Created Successfully.")
'MsgBox("Ticket Number: " + requestNumber + " Created Successfully.")
MsgBox(requestHandle, 3)
'Log off the server using the SID
ws1.logout(sid)
Just remember, the attributes need to be in pairs, Label & Label Data e.g."SUMMARY" & "Summary text". You will need to import the CA WebService into the project. I'm using MS Visual Web Developer 2008 Express to create my project.

I don't use VB.net actual but this is C# code that might help you understand how you can access to CA web-service and perform select quires directly to it. you can translate to VB.net it works the same way
You can find how to use web service as pdf here
and
You can find CA Reference to web-service here it contains description on all objects you might need
webServiceName.USD_WebService wsUSD = new webServiceName.USD_WebService();
string username = "user1" , password = "password";
int sid = 0;
string userhandle = null;
XmlDocument xDoc = new XmlDocument();
sid = wsUSD.login(username, password);
userhandle = wsUSD.getHandleForUserid(sid, username);
string userEmailID = "myMail#company.com";
string[] attrs = new string[7];
attrs[0] = "type.sym";
attrs[1] = "ref_num";
attrs[2] = "open_date";
attrs[3] = "description";
attrs[4] = "status.sym";
attrs[5] = "last_mod_dt";
attrs[6] = "persistent_id";
//here is the important part
//note: 'CL' means closed
//where the cr is Object ref to SQL database
xDoc.LoadXml(wsUSD.doSelect(sid, "cr", " customer.email_address = '" + userEmailID + "' AND status != 'CL'", -1, attrs));
//here is other queries you can use the same way
xDoc.LoadXml(wsUSD.doSelect(sid, "cr", " customer.userid = '" + userEmailID + "'", -1, attrs));
wsUSD.logout(sid);

Add a web reference to the web services wsdl in Visual Studio (under Solutions Explorer, right click on References and click Add Web Reference).
If you are moving across environments I would recommend a .xml config file to specify the endpoint url to the WSDL.
Here is what it might look like in C# based on my use of it:
using webreference1;
public class WSExample
{
USD_WebService ws = new USD_WebService();
//set url when creating web reference to avoid this step
ws.Url = "http://yoursite.com/webservice?wsdl";
}
Now the ws object will allow you to access all of the methods specified in the wsdl. You can use the createRequest() method to create a request.
CA provides a Technical Reference guide, which includes web service methods. Consult their support site. If this is something you use frequently, I would recommend creating wrappers to abstract away the use of blank arrays.
Feel free to contact me if you need any additional support

A few months ago I wrote some PowerShell functions to look at CA Service Catalog and tell me basic things, like requests that were pending my actions, update request form details, etc. To do that I saved the wsdl xml file, cooked a .cs and then a compiled a .dll file.
Normally, I'd use this PowerShell function to compile a dll:
function get-freshDll {
param($url,$outDir)
$wsdl = #(Resolve-Path "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64\wsdl.exe")[0].Path
$cscPath = #(Resolve-Path "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe")[0].Path
& $wsdl $url /out:$outDir"\WebService.cs"
& $cscPath /t:library /out:WebService.dll $outDir"\WebService.cs"
}
which works for the other CA stuff, just not Service Catalog (which is what I care about). For Service Catalog you have to save the wsdl file and chop out the DataHandler node (maybe someone else knows how to work with it, I gave up). After that the basic flow to create the dll is the same (just point wsdl.exe at the saved/edited wsdl file instead of the url) and then compile the dll with csc.exe. Add a reference for this dll to your C#/VB project. Working in Service Desk the PowerShell function above should work just like it is, just feed it the wsdl url and the dir where you want the dll to end up (you may also need to change the directories for your specific versions of netfx and .net).
Once the dll is mounted in your project you can use the Object Browser to see the methods that it contains. I'm still working it out myself (hence I found this post, and if you think Service Desk is hard to find examples for, try Service Catalog!). I don't have a good reference for Service Desk, sorry, but this is the .cs code (almost literally) that got the getRequests and getPendingActions methods to populate a GridView from the Service Catalog API. The aspx:
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:GridView ID="GridView2" runat="server">
</asp:GridView>
</asp:Content>
Keep in mind this is from a web app so there's a line missing from above:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" .... blahblah #%>
The .cs code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Http;
using System.Net.Http.Formatting;
namespace MyNamespace
{
public partial class MyRequestStuff : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
RequestServiceImplService reqService = new RequestServiceImplService();
reqService.CookieContainer = new System.Net.CookieContainer();
string user = "userid", password = "password", unit = "Unit";
reqService.Url = "http://servicecatalog/usm/services/RequestService?wsdl";
string session = reqService.logIn(user, password, unit);
var myRequests = reqService.getRequests(session);
var myPending = reqService.getPendingActions(session, user);
reqService.logOut(session);
GridView1.DataSource = myPending;
GridView1.DataBind();
GridView2.DataSource = myRequests;
GridView2.DataBind();
}
}
}
Like baultista and za7ef mention in their code, you'll need to create an USD_WebService object (instead of RequestServiceImplService) and use the methods available there (like getStatuses()), the functionality will be pretty similar (they are in PowerShell). I know it's not quite on point (e.g. SC instead of SD) but I hope that you or someone else finds this example useful.

Related

Check to see if currently connected to work network (ldap server)

Firstly, I apologize if i have raised this incorrectly or not quite to the rules. It is my first post.
Can someone please help with my issue.
I have an web application that is fully functioning and authorizes the user.
my problem is that i want to add a check when the site loads to see if the PC is currently connected to the work network. EG. when at home and not connected via VPN I want to redirect to an error page stating not connected to the AD Domain Network.
Currently the app just crashes with exception of "ldap server cannot be reached".
I hope this makes sense.
CODE ADDED
Imports Microsoft.VisualBasic
Imports System.Security.Principal
Imports System.DirectoryServices
Imports System.DirectoryServices.AccountManagement
Imports System.Configuration.ConfigurationManager
Public Class Gen
Dim DomUser As System.DirectoryServices.AccountManagement.UserPrincipal = System.DirectoryServices.AccountManagement.UserPrincipal.Current
Public ADUser As String = AppSettings("DomainPrefix").ToString & DomUser.SamAccountName
Public ADEmail As String = DomUser.EmailAddress
Public ADForname As String = DomUser.GivenName
Public ADSurname As String = DomUser.Surname
Public ADFullName As String = ADForname & " " & ADSurname
Public wi As WindowsIdentity = HttpContext.Current.User.Identity
End Class
Culprit line is
Dim DomUser As System.DirectoryServices.AccountManagement.UserPrincipal = System.DirectoryServices.AccountManagement.UserPrincipal.Current
The best approach is to use the proper OOP paradigm.
Public Function CheckLDAP() As Boolean
Dim DomUser As System.DirectoryServices.AccountManagement.UserPrincipal
Dim blnLDAPOk As Boolean = False
Try
DomUser = System.DirectoryServices.AccountManagement.UserPrincipal.Current
blnLDAPOk = True
Catch ex as Exception
' Perhaps Throw an exception to be handled
End Try
Return blnLDAPOk
End Function
From the class Gen, instantiate the class
Dim gLDAP = New Gen
If (gLDAP.CheckLDAP()) Then
' We are in
Else
' Whoops, no LDAP found
End If

Access winform variable from browsercontrol

I have an application in ASP.Net Ajax. I want to open it via a browsercontrol from a winform, and I wish to access a variable (username) that the user used to log in to the webform with. On load I would like to read that username and perform the rest of my webpage code on that browsercontrol using that username.
My ASP.Net Ajax has been published to a internal web server and the browsercontrol loads that IP address.
Is there any way to achieve this at all?
EDIT:
I have discovered the javascript extension: window.external
And I can call a C# procedure from the webpage using javascript with it, which is a start, but I need to retrieve a varaible from c# - this is where the problem comes in. I have tried the
var name = function window.external.GetGlobalVariable(MyGlobalProcedure, "Cannot Get Value");
But javascript error says the method cannot be applied to the object.
Your answer should be as follows:
Public Class Form1
Dim GlobalVar As String = "Your Name"
Dim YourBrowser As New WebBrowser
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
YourBrowser.Url = New Uri("Your URL address")
AddHandler YourBrowser.DocumentCompleted, AddressOf PageLoadComplete
End Sub
'The invokescript will only work once the HTML has finished loading itself into your WebBrowser
Sub PageLoadComplete()
'Must declare the string inside an array as the invokescript only allows an object to be sent
Dim VarToSend As String() = {GlobalVar}
YourBrowser.Document.InvokeScript("yourJavascriptfunction", VarToSend)
End Sub
The javascript section should look as follows:
<script type="text/javascript" language="javascript">
function userNameSet(name) {
$(document).ready(function() {
//variable now exists inside your WebBrowser client and can be used accordingly now
alert(name);
});
}
</script>
References for answer: http://www.dotnetcurry.com/showarticle.aspx?ID=194
"Store that name in a session variable and access the session in your ajax call"
In your ASP.Net application create a hidden field (or if it's somewhere on the UI in some control that works also). Put the username or whatever information you want to share into that field.
From your WinForms program you can request that field through the WebBrowser control like this:
MessageBox.Show(WebBrowser1.Document.GetElementById("txtUsername").GetAttribute("value"))
The above assumes you have some HTML element called txtUsername with the value attribute set.

Classic asp not publicly available

I need to call a classic asp page from .net, because I need the functionality of the classic asp page within my .net app.
The only way I know how to do that at the moment is like this :
MeetingCentres.Services.ClassicWhyGo.file_get_contents("http://someurl.asp?inputValue=£$%$£"%$£"%$£%)
public static string file_get_contents(string fileName)
{
string sContents = string.Empty;
if (fileName.ToLower().IndexOf("http:") > -1)
{ // URL
System.Net.WebClient wc = new System.Net.WebClient();
byte[] response = wc.DownloadData(fileName);
sContents = System.Text.Encoding.ASCII.GetString(response);
}
else
{
// Regular Filename
System.IO.StreamReader sr = new System.IO.StreamReader(fileName);
sContents = sr.ReadToEnd();
sr.Close();
}
return sContents;
}
...but this means that the classic asp page is accessed over http and hence publicly available.
How ever I need to protect this page somehow as sensitive information is returned.
I would prefer to not have this asp page publicly available.
In IIS there doesn't seem to be the ability to make the page available only above the website root, as far as I know?
Otherwise if it must be public was thinking that I may be able to check the ip address of the calling.net app and make sure that it is on the same server.
Is there a better way to do this? or would the above be safe..?
You are able to modify the .asp page?
Do some tests like:
Check if the IP address are the same:
<%
if Request.ServerVariables("REMOTE_ADDR") = "127.0.0.1" then
'Do your stuff
end if
%>
Create a Cookie, store a encoded key and test it and only show the data if the value equals the key.
<%
Response.Cookies("key")=encodedKey
%>
Test the cookie
<%
if Decode(Response.Cookies("key")) = decodedKey then
'Do your stuff
end if
%>
This are just simples ideas.

Create an Appointment with EWS in VB.NET, what am i missing?

Hello i want to send a calendar invite to other members, how can i do that in vb.net,
i added the exchange webreference and can send a normal mail to other people.
here is what i have so far
Public Sub Einladungen()
Dim esb As New ExchangeServer.ExchangeServiceBinding
esb.Credentials = New NetworkCredential(Session("EX_UserName").ToString, Session("EX_Password").ToString)
esb.Url = Session("EX_DomainURL")
Dim appointment As CalendarItemType = New CalendarItemType
' Set properties on the appointment.
appointment.Subject = "Dentist Appointment"
appointment.Body = New BodyType
appointment.Body.BodyType1 = BodyTypeType.Text
appointment.Body.Value = "Agenda Items...."
appointment.Start = New DateTime(2012, 3, 1, 9, 0, 0)
appointment.End = appointment.Start.AddHours(2)
appointment.Location = "Conf Room"
appointment.RequiredAttendees.Add("user1#contoso.com")
appointment.RequiredAttendees.Add("user2#contoso.com")
appointment.OptionalAttendees.Add("user3#contoso.com")
' Save the appointment.
appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy)
End Sub
Visual Studio tells me that:
Add is not a member of "System.Array"
and
"Save" is not a member of "ExchangeServer.CalendarItemType"
and
The name "SendInvitationMode" is not declared
What am i missing?
Thanks in advance for your help
The problem is that you have created your own EWS proxy classes by referencing your Exchange web service directly but the sample code you have found is built using the Exchange Web Service Managed API.
So what you should do is to download the EWS Managed API, add a reference to Microsoft.Exchange.WebServices.dll, and change the beginning of your code into something similar to this:
Dim esb As New ExchangeService(ExchangeVersion.Exchange2007_SP1);
esb.Credentials = New NetworkCredential(Session("EX_UserName").ToString, Session("EX_Password").ToString)
esb.Url = Session("EX_DomainURL")
Dim appointment As new Appointment(esb);
// ... the rest of your code here.
You might want to have a look at this example:
http://msdn.microsoft.com/en-us/library/exchange/dd633661(v=exchg.80).aspx

ASP.NET multi language website?

How can I transform a website to be able to handle multi language (example : english, french, spanish)?
I do not like the resource file because I feel limited and it's pretty long to build the list. Do you have any suggestion?
Update
For the moment the best way we found is to use an XML file and with some Xpath et get values.
Implicit localization (on the Visual Studio - Tools menu - Generate Local Resources) is about as easy as it can be. Write your pages in your default language, pick the menu option, and your resource files are created and can be sent to someone to translate.
The resx file is just xml, so if the translation company wants you can transform it into (and out of) spreadsheets easily.
Using a databases instead of resx as your backing store is not difficult. Rick Strahl has a good explanation and example code for a database-driven localization provider here - there's a nice built in localization editor too with interface to Google translations and Babelfish.
We store resources for multilingual sites in a database. We've created a couple of tools to make it easy to create and access these. There's a custom ExpressionBuilder that allows us to use this syntax:
<asp:linkbutton runat='server' text='<%$ LanguageStrings:ClickMe%>' />
And a custom label that contains the default text, and adds a row to the database if there's not already one.
<r:languagelabel runat="server" name="AboutUs">About Us</r:languagelabel>
The table containing the strings has one column per language. This makes it very easy to create the site in English (or whatever the default language is), then hand off the table (which populates itself) to a translator. It's also very easy to see what languages you need to have stuff translated for. With resources, every time you need to add a new string, you have to stop what you're doing, and then go to the resource file for each language and add the resource.
Here's the code for the language label:
''' <summary>
''' Retrieves a language-specific string.
''' </summary>
Public Class LanguageLabel
Inherits Label
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Private Sub Populate()
If Len(Me.Name) > 0 Then
Dim LanguageString As String = GetLanguageString(Me.Name, Me.Text)
If Len(LanguageString) > 0 Then Me.Text = LanguageString
End If
End Sub
Private Sub LanguageLabel_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Populate()
End Sub
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
' By default a label wraps the text in a <span>, which we don't want in some situations
writer.Write(Me.Text)
End Sub
End Class
and the utility function:
Public Function GetLanguageString(ByVal Name As String, Optional ByVal DefaultText As String = "") As String
Dim DefaultLanguage As Language = Languages.GetById(1)
Name = StripPunctuation(Name).Trim.Replace(" ", "") ' Remove punctuation, spaces from name
Dim SelectSql As String = String.Format("Select {0},{1} from LanguageStrings where Name=#Name", Languages.CurrentLanguage.Code, DefaultLanguage.Code)
Dim LanguageStringTable As DataTable = ExecuteDataset(cs, CommandType.Text, SelectSql, New SqlParameter("#Name", Name)).Tables(0)
If LanguageStringTable IsNot Nothing AndAlso LanguageStringTable.Rows.Count > 0 Then
Dim LanguageText As String = LanguageStringTable.Rows(0)(Languages.CurrentLanguage.Code).ToString
Dim DefaultLanguageText As String = LanguageStringTable.Rows(0)(DefaultLanguage.Code).ToString
If Len(LanguageText) > 0 Then
' We have a string in this language
Return LanguageText
Else
' Nothing in this language - return default language value
Return DefaultLanguageText
End If
Else
' No record with this name - create a dummy one
If DefaultText = "" Then DefaultText = Name
Dim InsertSql As String = String.Format("Insert into LanguageStrings (Name, {0}) values (#Name, #Text)", DefaultLanguage.Code)
ExecuteNonQuery(cs, CommandType.Text, InsertSql, New SqlParameter("#Name", Name), New SqlParameter("#Text", DefaultText))
Return Name
End If
End Function
Resource files are the way to go. We ship our product in 12 languages. We pull all strings out into resource files and ship them to a translation company. It's a pain at times, but that is the defacto way to do it.
It also gets fun when 4-letter English words get translated into 17-letter phrases and you have to tweak your UI.
How late in the design process are you? If not too late, and if the budget allows, consider porting to a multi-lingual CMS like Ektron CMS300.net (which has built-in translation tools). If not, then you've got a huge task ahead of you.
Another solution I am using is to create the language folders which contain the aspx pages containing all the required text in that particular language.
The only problem here is how can you inject as little code as possible into those replicating pages. I am using a controller pattern here to do this, and then a object data source to get the data and bind it to the controls in all pages.
In this way I have achieved the goal of getting rid of the resource files and I can keep the code behind in one place without replicating it (unless necessary).
Edit: I would recommend a good CMS framework as well.
One of the web apps I develop has this NLS requirement too.
I found that there are at least 3 locations where you have localized texts:
user interface
database tables ("catalogs" or whatever you want to call them)
backend code (services etc)
My solution has one table for the pages, tables, etc ("Container"), one table for each item in that container (e.g. labels, buttons by ID, record identifiers), and one table for the translated items (plus language identifier).
A translation application helps me keep the translations up-to-date, and exports all translations in XML.
The product ships with translations, but customers can adjust the translations, changes taking effect immediately.
Sample code i have done using resource file
add global.asax
void Application_BeginRequest(Object sender, EventArgs e)
{
// Code that runs on application startup
HttpCookie cookie = HttpContext.Current.Request.Cookies["CultureInfo"];
if (cookie != null && cookie.Value != null)
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cookie.Value);
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cookie.Value);
}
else
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en");
}
}
http://satindersinght.blogspot.in/2012/06/create-website-for-multilanguage.html
http://satindersinght.wordpress.com/2012/06/14/create-website-for-multilanguage-support/

Resources