Forfatter |
Emne |
[+35]6-shooter_X
[+35] co-Clan Founder, [+35] Member of COW
4556 Posts |
Skrevet - 01 Nov 2005 : 10:28:48
|
Kald af webservice...
Gem som "callws.cs" og kør "csc callws.cs" Kør callws.exe
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Xml.Serialization;
using System.Web.Services.Protocols;
using System.Web.Services;
namespace HelloWorldApp
{
class HelloWorld
{
[STAThread]
static void Main()
{
Application.Run(new HWForm());
}
} // HelloWorld
public class HWForm : Form
{
private Button btnExit;
private Button btnCallHW;
private Label lblHW;
public HWForm()
{
btnExit = new System.Windows.Forms.Button();
btnExit.Location = new System.Drawing.Point(102, 83);
btnExit.Size = new System.Drawing.Size(100, 23);
btnExit.Text = "Exit";
btnExit.Click += new System.EventHandler(btnExit_Click);
btnCallHW = new System.Windows.Forms.Button();
btnCallHW.Location = new System.Drawing.Point(102, 113);
btnCallHW.Size = new System.Drawing.Size(100, 23);
btnCallHW.Text = "Call Webservice HW";
btnCallHW.Click += new System.EventHandler(btnCallHW_Click);
lblHW = new System.Windows.Forms.Label();
lblHW.AutoSize = true;
lblHW.Location = new System.Drawing.Point(99, 32);
lblHW.Text = "Hello World!!";
ClientSize = new System.Drawing.Size(384, 165);
Controls.Add(this.lblHW);
Controls.Add(this.btnExit);
Controls.Add(this.btnCallHW);
Text = "Hello world !!";
}
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnCallHW_Click(object sender, EventArgs e)
{
HelloWorldWS ws = new HelloWorldWS();
Text = "Received : '"+ ws.HelloWorld() +"' from Webservice";
}
} // HWForm
[System.Web.Services.WebServiceBindingAttribute(Name="Service1Soap", Namespace="http://clan35.learns.dotnet/")]
public class HelloWorldWS : System.Web.Services.Protocols.SoapHttpClientProtocol
{
public HelloWorldWS()
{
this.Url = "http://localhost/wshelloworld/helloworld.asmx";
}
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://clan35.learns.dotnet/HelloWorld", RequestNamespace="http://clan35.learns.dotnet/", ResponseNamespace="http://clan35.learns.dotnet/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string HelloWorld()
{
object[] results = this.Invoke("HelloWorld", new object[0]);
return ((string)(results[0]));
}
} // HelloWorldWS
}
|
**** Cow(ard) of the county ****
|
|
|
[+35]6-shooter_X
[+35] co-Clan Founder, [+35] Member of COW
4556 Posts |
Skrevet - 01 Nov 2005 : 22:23:33
|
Assemblies. Opdeling af programmet.
Først det modul der skal kaldes:
using System;
namespace HelloWorldApp
{
public class HelloWorldClass
{
public HelloWorldClass()
{
}
public void SayIt()
{
Console.WriteLine("Hello world !!!");
}
}
}
gemmes som hwclass.cs og compileres med : csc /t:library hwclass.cs
"/t:library" betyder at der skal genereres et dll, uden main-funktion. "/t:exe" betyder at der skal genereres et exe-modul og der checkes for et en gyldig main-metode. "/t:exe" er default
Og så det kaldende program:
using System;
namespace HelloWorldApp
{
class HWMain
{
static void Main()
{
HelloWorldClass hw = new HelloWorldClass();
hw.SayIt();
}
}
}
gemmes som main.cs og compileres med : csc /r:hwclass.dll main.cs
"/r:hwclass.dll" betyder at der skal ledes efter program-"stumper" i hwclass.dll
Kør main.exe |
**** Cow(ard) of the county ****
|
|
|
[+35]Terabyte
[+35] Soldier
Denmark
2730 Posts |
Skrevet - 01 Nov 2005 : 22:54:46
|
ok - jeg er med hertil |
|
|
[+35]Tomcat
[+35] Soldier
Denmark
1309 Posts |
Skrevet - 02 Nov 2005 : 05:16:10
|
det kan jeg roligt sige jeg ikke er, men checker alligevel den her tråd troligt hver dag man er vel ikke nørd for ingenting |
Tc over´n´out ! |
|
|
[+35]6-shooter_X
[+35] co-Clan Founder, [+35] Member of COW
4556 Posts |
Skrevet - 02 Nov 2005 : 11:29:44
|
En Windows Service.
Skriver til application-eventlog hvert 10. sekund.
Gem som hwservice.cs
using System;
using System.Windows.Forms;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.ServiceProcess;
using System.Configuration.Install;
namespace HelloWorldApp
{
public class HelloWorldSvc : System.ServiceProcess.ServiceBase
{
private System.Timers.Timer timer;
public HelloWorldSvc()
{
timer = new System.Timers.Timer();
timer.Interval = 10000; // Gør noget hver t 10. sekund
timer.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_Elapsed);
CanPauseAndContinue = true;
CanShutdown = true;
ServiceName = "HelloWorld_Service";
timer.Enabled = true;
timer.Start();
}
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new HelloWorldSvc() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
protected override void OnStart(string[] args)
{
timer.Start();
}
protected override void OnPause()
{
timer.Stop();
}
protected override void OnContinue()
{
timer.Start();
}
protected override void OnStop()
{
timer.Stop();
}
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
EventLog.WriteEntry("C# gets the job done on: " + System.Environment.MachineName);
}
}
[RunInstaller(true)]
public class ProjectInstaller : System.Configuration.Install.Installer
{
private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller;
private System.ServiceProcess.ServiceInstaller serviceInstaller;
public ProjectInstaller()
{
serviceProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
serviceInstaller = new System.ServiceProcess.ServiceInstaller();
serviceInstaller.StartType = ServiceStartMode.Automatic;
serviceInstaller.ServiceName = "HelloWorld_Service";
serviceInstaller.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.serviceInstaller_AfterInstall);
Installers.AddRange(new System.Configuration.Install.Installer[] { serviceProcessInstaller, serviceInstaller });
}
private void serviceInstaller_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)
{
MessageBox.Show(serviceInstaller.ServiceName + " succesfully installed...");
}
}
}
Oversæt med csc hwservice.cs
Gæt hvad de næste filer gør :)
Gem denne som INSTALL.CMD
installutil hwservice.exe
Gem denne som UNINSTALL.CMD
installutil /uninstall hwservice.exe
installutil /u hwservice.exe
Gem denne som STARTSVC.CMD
net start "HelloWorld_Service"
Gem denne som STOPSVC.CMD
net stop "HelloWorld_Service"
|
**** Cow(ard) of the county ****
|
|
|
[+35]6-shooter_X
[+35] co-Clan Founder, [+35] Member of COW
4556 Posts |
Skrevet - 07 Nov 2005 : 15:48:28
|
Lidt med XML
Gem som "HelloWorldXML.cs" og Oversæt med "csc HelloWorldXML.cs"
using System;
using System.Xml;
namespace HelloWorldXML
{
public class HelloWorldApp
{
[STAThread]
static void Main()
{
string infilename = "hw.xml";
XmlDocument doc = new XmlDocument();
XmlTextReader tr = new XmlTextReader(infilename);
doc.Load(tr);
foreach (XmlNode xe in doc.SelectNodes("//*"))
if (xe.Name == "MessageToTheWorld")
{
string Recipient = "";
string Message = "";
string Sender = "";
foreach (XmlNode xn in xe.ChildNodes)
{
switch (xn.Name.ToLower())
{
case "recipient" : Recipient = xn.InnerText; break;
case "message" : Message = xn.InnerText; break;
case "sender" : Sender = xn.InnerText; break;
}
}
Console.WriteLine("To : " + Recipient);
Console.WriteLine("Message : " + Message);
Console.WriteLine("From : " + Sender);
Console.WriteLine("");
}
}
}
}
Og gem denne som "hw.xml"
<?xml version="1.0" encoding="UTF-8"?>
<MessagesToTheWorld>
<MessageToTheWorld>
<Recipient>Whoom it may concern</Recipient>
<Message>Hello world!</Message>
<Sender>[+35]</Sender>
</MessageToTheWorld>
<MessageToTheWorld>
<Recipient>COW</Recipient>
<Message>I er dumme!</Message>
<Sender>Miss Piggy</Sender>
</MessageToTheWorld>
</MessagesToTheWorld>
|
**** Cow(ard) of the county ****
|
|
|
[+35]6-shooter_X
[+35] co-Clan Founder, [+35] Member of COW
4556 Posts |
Skrevet - 08 Nov 2005 : 11:19:21
|
Lidt med XML, som database. + Opdatering
Gem som "HelloWorldDataXML.cs" og Oversæt med "csc HelloWorldXMLXML.cs"
using System;
using System.Data;
namespace HelloWorldDataXML
{
public class HelloWorldApp
{
[STAThread]
static void Main()
{
DataSet ds = new DataSet();
ds.ReadXml("hw.xml", XmlReadMode.InferSchema);
foreach (DataRow dr in ds.Tables[0].Rows)
{
Console.WriteLine("To : " + dr["Recipient"]);
Console.WriteLine("Message : " + dr["Message"]);
Console.WriteLine("From : " + dr["Sender"]);
Console.WriteLine("");
}
DataRow NewRow = ds.Tables[0].NewRow();
NewRow["Recipient"] = "Miss Piggy";
NewRow["Message"] = "Ehmm. hvad skal man sige?";
NewRow["Sender"] = "[+35]COW";
ds.Tables[0].Rows.Add(NewRow);
ds.WriteXml("hw.xml");
}
}
}
Og gem denne som "hw.xml"
<?xml version="1.0" encoding="UTF-8"?>
<MessagesToTheWorld>
<MessageToTheWorld>
<Recipient>Whoom it may concern</Recipient>
<Message>Hello world!</Message>
<Sender>[+35]</Sender>
</MessageToTheWorld>
<MessageToTheWorld>
<Recipient>COW</Recipient>
<Message>I er dumme!</Message>
<Sender>Miss Piggy</Sender>
</MessageToTheWorld>
</MessagesToTheWorld>
|
**** Cow(ard) of the county ****
|
|
|
[+35]TheBeerMan
[+35] Soldier
Denmark
185 Posts |
Skrevet - 13 Aug 2006 : 11:30:07
|
Hvorfor læste jeg lige alt dette ? edderrøvme tørt :-) go lyst gutter |
If you are going my way? ---- i stay here !
(Marx Brothers) |
|
|
[+35]Terabyte
[+35] Soldier
Denmark
2730 Posts |
Skrevet - 13 Aug 2006 : 22:49:03
|
Lol Beerman
Du er da rundt i de gamle arkiver
Når det bliver vintertid igen må vi have denne her vækket til live igen og så er du velkommen til at følge lidt med
|
|
|
Emne |
|