using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Configuration;
using Microsoft.Uddi;
using Microsoft.Uddi.Api;
using MSSOAPLib30;
namespace WebApplication2
{
///
/// Summary description for WebForm1.
///
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label HoroscopeTypeLabel;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.Label rangeLabel;
protected System.Web.UI.WebControls.Label commentsLabel;
protected System.Web.UI.WebControls.Label resultLabel;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DropDownList MonthDropDownList;
protected System.Web.UI.WebControls.Label astroFieldDebug;
protected System.Web.UI.WebControls.Label rangeFieldDebug;
protected System.Web.UI.WebControls.Label bdayFieldDebug;
protected System.Web.UI.WebControls.Label emailFieldDebug;
protected System.Web.UI.WebControls.Label debuggingLabel;
protected System.Web.UI.WebControls.Button publish;
protected System.Web.UI.WebControls.Button discover;
protected System.Web.UI.WebControls.Image Image2;
protected System.Web.UI.WebControls.DropDownList DayDropDownList;
protected System.Web.UI.WebControls.DropDownList YearDropDownList;
//Variables for UDDI discovery and publish
string passportUserId="JimboBimbo_699@hotmail.com",
passportPassword=@"nretni",
inquireUrl="http://test.uddi.microsoft.com/inquire",
publishUrl="https://test.uddi.microsoft.com/publish",
//mind the HTTPS for publishing
webService=
"http://dream.sims.berkeley.edu:8080/axis/services/HSSoap?wsdl";
static string wsUri;
protected System.Web.UI.WebControls.Label PubDiscLabel;
protected System.Web.UI.WebControls.Label PerformanceLabel;
protected System.Web.UI.WebControls.Label PerformanceNumLabel;
protected System.Web.UI.WebControls.Label Label2;
string serviceProvider= "Cal Berkeley SIMS web services course - Vam and Tu";
//our test service provider name
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (! IsPostBack)
{
//string[] hor_types = new string[]{"Vedic","Chinese", "All"};
DropDownList1.Items.Add("Chinese");
DropDownList1.Items.Add("Vedic");
DropDownList1.Items.Add("All");
//ListItem[] range_types = new ListItem[]{"daily","monthly", "yearly"};
//this.DropDownList2.Items.AddRange(range_types);
DropDownList2.Items.Add("Daily");
DropDownList2.Items.Add("Monthly");
DropDownList2.Items.Add("Yearly");
for (int i=1; i <= 9; i++)
{
MonthDropDownList.Items.Add("0" + i.ToString());
}
for (int i=10; i <= 12; i++)
{
MonthDropDownList.Items.Add(i.ToString());
}
for (int i=1; i <= 9; i++)
{
DayDropDownList.Items.Add("0" + i.ToString());
}
for (int i=10; i <= 31; i++)
{
DayDropDownList.Items.Add(i.ToString());
}
for (int i=1950; i <= 2004; i++)
{
YearDropDownList.Items.Add(i.ToString());
}
System.Console.WriteLine("BOO\n");
}
}//end Page_Load
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.DropDownList2.SelectedIndexChanged += new System.EventHandler(this.DropDownList2_SelectedIndexChanged);
this.TextBox2.TextChanged += new System.EventHandler(this.TextBox2_TextChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.publish.Click += new System.EventHandler(this.publish_Click);
this.discover.Click += new System.EventHandler(this.discover_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
//Horoscope drop down list
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
//Submit button
private void Button1_Click(object sender, System.EventArgs e)
{
//On submit clear discovery and publish labels
PubDiscLabel.Text="";
//On submit clear comments label
commentsLabel.Text="";
//clear result label
resultLabel.Text="";
//clear ms displayed
PerformanceNumLabel.Text="";
//clear debugging label
debuggingLabel.Text="";
/*
* Performance Measure: elapsedMS is a number of milliseconds.
* It will represent the number of ms between a time a response was requested
* and received.
* */
int elapsedMS = 0;
//Create service, request, and response objects
WebApplication2.HoroscopeService.HoroscopeService service = new WebApplication2.HoroscopeService.HoroscopeService();
WebApplication2.HoroscopeService.HoroscopeRequestType request = new WebApplication2.HoroscopeService.HoroscopeRequestType();
WebApplication2.HoroscopeService.HoroscopeResponseType response = new WebApplication2.HoroscopeService.HoroscopeResponseType();
try
{
//The input strings from UI
string horoscopeInput;
string rangeInput;
string bdayInput;
string emailInput;
//Get horoscope and range inputs from UI
horoscopeInput = DropDownList1.SelectedItem.ToString();
rangeInput = DropDownList2.SelectedItem.ToString();
//Extract and confirm birthday format.
//Note this does not account for leap years and February's varying num of days.
string month = MonthDropDownList.SelectedItem.ToString();
string day = DayDropDownList.SelectedItem.ToString();
//if month is 02 then day != 30 or 31
if (month == "02" && (day == "30" || day =="31"))
{
commentsLabel.Text = "February cannot have more than 29 days. Please re-enter.";
return;
}
//if month is 04, 06, 09, 11, then day cannot be > 30
if (((month == "04") || (month == "06") || (month == "09") || (month == "11")) && (day == "31"))
{
commentsLabel.Text = "Your month cannot have 31 days. Please re-enter.";
return;
}
//Get Year from drop down list
string year = YearDropDownList.SelectedItem.ToString();
bdayInput = month + "/" + day + "/" + year;
//Extract email
emailInput=TextBox2.Text;
//check if emailInput is blank and request entry
if (emailInput == "")
{
commentsLabel.Text = "PLEASE ENTER AN EMAIL ADDRESS";
return;
}
/*
* WS Addressing - Create instances of header class
*
* */
ReplyTo replyHeader = new ReplyTo();
To toHeader = new To();
Action actionHeader = new Action();
//WS Addressing
//Populate header replyto with emailInput
replyHeader.Address = emailInput;
toHeader.Address = "http://dream.sims.berkeley.edu:8080/axis/services/HSSoap";
actionHeader.action = "http://dream.sims.berkeley.edu:8080/axis/services/HSSoap#getHoroscope";
service.ReplyTo = replyHeader;
service.To = toHeader ;
service.Action = actionHeader;
/*
* Populate request
* */
try
{
//Populate the request HoroscopeType and Range
request.HoroscopeType = horoscopeInput;
request.Range = rangeInput;
request.Birthday = bdayInput;
request.Email = emailInput;
/*
//Debugging - check if request is null.
if (request == null)
{
debuggingLabel.Text += " - Request is null";
return;
}
else
{
debuggingLabel.Text += " - Request is NOT null";
}
*/
}
catch (Exception ex)
{
debuggingLabel.Text += "Error on request population!" + ex;
return;
}
//Synchronous call to service
//Performance check - Get time before getHoroscope call
DateTime start = DateTime.Now;
try
{
//Populate response from getHoroscope call
response = service.getHoroscope(request);
//call this for demo purposes since response can't be populated
//service.getHoroscope(request);
//Get time after getHoroscope call
elapsedMS = (int)((TimeSpan)(DateTime.Now - start)).TotalMilliseconds;
}
catch
{
debuggingLabel.Text += "error on populating response with request...";
}
//For demo purposes
if (response == null && horoscopeInput=="Chinese" && rangeInput=="Daily" && bdayInput=="01/01/1960")
{
//For demo purposes
response = new WebApplication2.HoroscopeService.HoroscopeResponseType();
response.HoroscopeType = horoscopeInput;
response.Range = rangeInput;
response.Birthday = bdayInput;
response.Email = emailInput;
//This is the Chinese horoscope result for 01/01/1960
response.Summary = "Unexpected delays will complicate matters in your work; try to keep your cool. Be tolerant and understanding, otherwise you won't escape domestic squabbles. Single people will be favored by fortune heartwise. Concerning your speculations, caution will be necessary. Avoid letting money slip away between your fingers. Try to eat in the most wholesome way possible so as to promote your health.";
resultLabel.Text= response.Summary ;
}
/*
//Commented out since response cannot be populated
//Asynchronous call to the service
try
{
DateTime start = DateTime.Now;
IAsyncResult asynch = service.BegingetHoroscope(request,null,null);
while (!asynch.IsCompleted)
{
System.Threading.Thread.Sleep(250);
}
response = service.EndgetHoroscope(asynch);
elapsedMS = (int)((TimeSpan)(DateTime.Now - start)).TotalMilliseconds;
}
catch
{
commentsLabel.Text += "Error: on response";
}
*/
//Print elapsed time to client UI
PerformanceNumLabel.Text = elapsedMS.ToString();
}//end try for method
catch
{
commentsLabel.Text = "Error: Horoscope could not be returned.";
}
}
private void DropDownList2_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
private void TextBox1_TextChanged(object sender, System.EventArgs e)
{
}
private void TextBox2_TextChanged(object sender, System.EventArgs e)
{
}
private void publish_Click(object sender, System.EventArgs e)
{
PubDiscLabel.Text = "";
try
{
Publish.Url = publishUrl;
Publish.User = passportUserId;
Publish.Password = passportPassword;
SaveBusiness sb = new SaveBusiness();
sb.BusinessEntities.Add();
sb.BusinessEntities[0].Names.Add(serviceProvider);
sb.BusinessEntities[0].Descriptions.Add("en",
"This business is all about getting horoscopes.");
//our original uid
//sb.BusinessEntities[0].CategoryBag.Add("California",
// "US-SA", "uuid:f1297f4f-9b47-4e38-a8a7-8475e5b9671b");
// Add contact details for responsible/support people
sb.BusinessEntities[0].Contacts.Add();
sb.BusinessEntities[0].Contacts[0].PersonName = "Tu";
sb.BusinessEntities[0].Contacts[0].UseType = "CEO";
sb.BusinessEntities[0].Contacts[0].Addresses.Add("#code", "PBMS");
sb.BusinessEntities[0].Contacts[0].Addresses[0].AddressLines.Add(
"South Hall - UC Berkeley");
sb.BusinessEntities[0].Contacts[0].Addresses[0].AddressLines.Add(
"Berkeley");
sb.BusinessEntities[0].Contacts.Add("Vam","CTO");
//UseType specified in IInd parameter
// Add service details
sb.BusinessEntities[0].BusinessServices.Add();
sb.BusinessEntities[0].BusinessServices[0].Names.Add("horoscope");
sb.BusinessEntities[0].BusinessServices[0].Descriptions.Add(
"multi-cultural horsocopes!");
// Specify a binding where the service can be located
sb.BusinessEntities[0].BusinessServices[0]
.BindingTemplates.Add();
sb.BusinessEntities[0].BusinessServices[0].
BindingTemplates[0].AccessPoint.Text = webService;
sb.BusinessEntities[0].BusinessServices[0].
BindingTemplates[0].AccessPoint.URLType =
Microsoft.Uddi.Api.URLType.Http;
sb.BusinessEntities[0].BusinessServices[0].
BindingTemplates[0].Descriptions.Add(
"Retrieves your Vedic and Chinese horoscopes");
// Send the built save business request
BusinessDetail businessDetail = sb.Send();
// Print the generated business key
PubDiscLabel.Text += "Business: " +
businessDetail.BusinessEntities[0].Names[0].Text;
PubDiscLabel.Text += " Key: " +
businessDetail.BusinessEntities[0].BusinessKey;
PubDiscLabel.Text += " Service published in Microsoft test UDDI site";
}
catch (UddiException ex)
{
if(ex.Number==UddiException.ErrorType.E_accountLimitExceeded)
PubDiscLabel.Text = "Publish Request: Service Provider "+
serviceProvider+" already exists";
else if(ex.Number==UddiException.ErrorType.E_unknownUser)
PubDiscLabel.Text = "UDDI Exception: Passport authentication failed,"+
" double check your userId ("+passportUserId+
") and password ("+passportPassword+")";
else
PubDiscLabel.Text = "UDDI exception: " + ex.Number + " - " + ex.Message;
}
catch (Exception ex)
{Response.Write("Other exception: " + ex.Message);}
}
private void discover_Click(object sender, System.EventArgs e)
{
try
{
Inquire.Url = inquireUrl;
// Create an object to find a business
FindBusiness fb = new FindBusiness();
fb.Names.Add(serviceProvider);
// Send the prepared find business request
BusinessList businessList = fb.Send();
if (businessList.BusinessInfos.Count>0)
{
GetBusinessDetail detailObject = new GetBusinessDetail();
// Associate the business key with detailObject, returned by fb.Send call
detailObject.BusinessKeys.Add(businessList.BusinessInfos[0].BusinessKey);
// Send the request to the UBR node
BusinessDetail businessDetail = detailObject.Send();
//Scan through all business entities returned
if (businessDetail.BusinessEntities.Count>0)
{
// Scan categories specified for this business
for (int i=0; i < businessDetail.BusinessEntities[0].CategoryBag.Count; i++)
{
PubDiscLabel.Text += "
Categories: ";
PubDiscLabel.Text += "
Name : " + businessDetail.BusinessEntities[0].CategoryBag[i].KeyName;
PubDiscLabel.Text += "
Value : " + businessDetail.BusinessEntities[0].CategoryBag[i].KeyValue;
PubDiscLabel.Text += "
tModel : " + businessDetail.BusinessEntities[0].CategoryBag[i].TModelKey;
}
// Scan identifiers for the same
for (int j=0; j < businessDetail.BusinessEntities[0].IdentifierBag.Count; j++)
{
PubDiscLabel.Text += "
Identifiers:";
PubDiscLabel.Text += "
Name : " + businessDetail.BusinessEntities[0].IdentifierBag[j].KeyName;
PubDiscLabel.Text += "
Value : " + businessDetail.BusinessEntities[0].IdentifierBag[j].KeyValue;
PubDiscLabel.Text += "
tModel : " + businessDetail.BusinessEntities[0].IdentifierBag[j].TModelKey;
}
// scan contacts
for (int k=0; k < businessDetail.BusinessEntities[0].Contacts.Count; k++)
{
PubDiscLabel.Text += "
Contact ("+(k+1)+"):" ;
PubDiscLabel.Text += "
Name : " + businessDetail.BusinessEntities[0].Contacts[k].PersonName;
PubDiscLabel.Text += "
Type : " + businessDetail.BusinessEntities[0].Contacts[k].UseType;
}
// Scan through business services
for (int m=0; m < businessDetail.BusinessEntities[0].BusinessServices.Count; m++)
{
PubDiscLabel.Text += "
Services Discovered...";
PubDiscLabel.Text += "
Name : " + businessDetail.BusinessEntities[0].BusinessServices[m].Names[0].Text;
// There might be multiple access points for this service
for (int n=0; n < businessDetail.BusinessEntities[0].BusinessServices[m].BindingTemplates.Count; n++)
{
//display and put the AccessPoint in variable wsUri
PubDiscLabel.Text += "
Access point : " + (businessDetail.BusinessEntities[0].BusinessServices[m].BindingTemplates[n].AccessPoint.Text);
wsUri=businessDetail.BusinessEntities[0].BusinessServices[m].BindingTemplates[n].AccessPoint.Text;
}
}
}
}
}
catch (UddiException er)
{Response.Write("UDDI exception: (" + er.Number + ") - " + er.Message);}
catch (Exception er)
{Response.Write("Other exception: " + er.Message);}
}
private void DropDownList3_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
}
}