Thứ Hai, 11 tháng 8, 2008

Add and Call WebService at runtime

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Security.Permissions;
using System.Web.Services.Description;

namespace ConnectionLib
{
internal class WsProxy
{
[SecurityPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]
internal static object CallWebService(string webServiceAsmxUrl, string serviceName, string methodName, object[] args)
{
System.Net.WebClient client = new System.Net.WebClient(); // Connect To the web service
System.IO.Stream stream = client.OpenRead(webServiceAsmxUrl + "?wsdl"); // Now read the WSDL file describing a service.
ServiceDescription description = ServiceDescription.Read(stream); ///// LOAD THE DOM ///////// // Initialize a service description importer.

ServiceDescriptionImporter importer = new ServiceDescriptionImporter();

importer.ProtocolName = "Soap12"; // Use SOAP 1.2.
importer.AddServiceDescription(description, null, null); // Generate a proxy client. importer.Style = ServiceDescriptionImportStyle.Client; // Generate properties to represent primitive values.
importer.CodeGenerationOptions = System.Xml.Serialization.CodeGenerationOptions.GenerateProperties; // Initialize a Code-DOM tree into which we will import the service.
CodeNamespace nmspace = new CodeNamespace();
CodeCompileUnit unit1 = new CodeCompileUnit();
unit1.Namespaces.Add(nmspace); // Import the service into the Code-DOM tree. This creates proxy code that uses the service.
ServiceDescriptionImportWarnings warning = importer.Import(nmspace, unit1); if (warning == 0) // If zero then we are good to go
{
// Generate the proxy code
CodeDomProvider provider1 = CodeDomProvider.CreateProvider("CSharp"); // Compile the assembly proxy with the appropriate references
string[] assemblyReferences = new string[5] { "System.dll", "System.Web.Services.dll", "System.Web.dll", "System.Xml.dll", "System.Data.dll" };
CompilerParameters parms = new CompilerParameters(assemblyReferences); CompilerResults results = provider1.CompileAssemblyFromDom(parms, unit1); // Check For Errors
if (results.Errors.Count > 0)
{ foreach (CompilerError oops in results.Errors)
{ System.Diagnostics.Debug.WriteLine("========Compiler error============");
System.Diagnostics.Debug.WriteLine(oops.ErrorText);
}
throw new System.Exception("Compile Error Occured calling webservice. Check Debug ouput window.");
}
// Finally, Invoke the web service method
object wsvcClass = results.CompiledAssembly.CreateInstance(serviceName);
MethodInfo mi = wsvcClass.GetType().GetMethod(methodName);
return mi.Invoke(wsvcClass, args);
}
else
{ return null;
}
}
}
}

Các câu lệnh chạy từ Run

Các câu lệnh chạy từ Run

- Accessibility Controls ( chương trình cơ bản trong Win)
access.cpl

- Add Hardware Wizard ( Tự dò tìm phần cứng)
hdwwiz.cpl

- Add/Remove Programs ( Thêm hoặc gỡ bỏ chương trình)
appwiz.cpl

- Administrative Tools ( công cụ quản trị̣)
control admintools

- Automatic Updates ( tự động cập nhật)
wuaucpl.cpl

- Bluetooth Transfer Wizard ( khởi động Bluetooth)
fsquirt

- Calculator ( máy tính )
calc

- Certificate Managercertmgr.msc- Character Map ( bảng ký tự)
charmap

- Check Disk Utility ( kiểm tra đĩa)
chkdsk

- Clipboard Viewer ( mở clipboard)
clipbrd

- Command Prompt (mở cửa sổ Dos)
cmd

- Component Services ( quản lý các thành phần )
dcomcnfg

- Computer Management (quản lý máy)
compmgmt.msc

- Date and Time Properties ( thuộc tính ngày giờ)
timedate.cpl

- DDE Shares ( chia sẻ DDE)
ddeshare

- Device Manager ( quản lý thiết bịdevmgmt.msc- Direct X Control Panel (If Installed)*directx.cpl

- Direct X Troubleshooterdxdiag- Disk Cleanup Utility ( quét rác)
cleanmgr

- Disk Defragment ( chống phân mảnh đĩa)
dfrg.msc

- Disk Management (quản lý đĩa)
diskmgmt.msc

- Disk Partition Manager (quản lý phân vùng)
diskpart

Display Propertiescontrol desktopDisplay Properties
desk.cpl

Display Properties (w/Appearance Tab Preselected)

control color

- Dr. Watson System Troubleshooting Utility (sử lý lỗi hệ thống)
drwtsn32

- Driver Verifier Utility
verifier

- Event
Viewereventvwr.msc

- File Signature Verification Tool
sigverif

- Findfastfindfast.cpl

- Folders Properties
control folders

- Fonts
control fonts

- Fonts
Folderfonts

- Free Cell Card Game
freecell

- Game
Controllersjoy.cpl

- Group Policy Editor (XP Prof)
gpedit.msc

- Hearts Card Game
mshearts

- Iexpress Wizard
iexpress

- Indexing Service
ciadv.msc

- Internet Properties
inetcpl.cpl

- IP Configuration (Display Connection Configuration)
ipconfig /all

- IP Configuration (Display DNS Cache Contents)
ipconfig /displaydns

- IP Configuration (Delete DNS Cache Contents)
ipconfig /flushdns

- IP Configuration (Release All Connections)
ipconfig /release

- IP Configuration (Renew All Connections)
ipconfig /renew

- IP Configuration (Refreshes DHCP & Re-Registers DNS)
ipconfig /registerdns

- IP Configuration (Display DHCP Class ID)
ipconfig /showclassid

- IP Configuration (Modifies DHCP Class ID)
ipconfig /setclassid- ava

Control Panel (If Installed)
jpicpl32.cpl

- Java Control Panel (If Installed)
javaws

- Keyboard Properties
control keyboard

- Local Security Settings
secpol.msc

- Local Users and Group
slusrmgr.msc

- Logs You Out Of Windows
logoff

- Microsoft Chat
winchat

- Minesweeper Game
winmine

- Mouse Properties
control mouse

- Mouse Properties
main.cpl

- Network Connections
control netconnections

- Network Connections
ncpa.cpl

- Network Setup Wizard
netsetup.cpl

- Notepad
notepad

- Nview Desktop Manager (If Installed)
nvtuicpl.cpl

- Object Packager
packager

- ODBC Data Source Administrator
odbccp32.cpl

- On Screen Keyboard
osk

- Opens AC3 Filter (If Installed)
ac3filter.cpl

- Password Properties
password.cpl

- Performance Monitor
perfmon.msc

- Performance Monitor
perfmon

- Phone and Modem
Optionstelephon.cpl

- Power Configuration
powercfg.cpl

- Printers and Faxes
control printers

- Printers Folder
printers

- Private Character Editor
eudcedit

- Quicktime (If Installed)
QuickTime.cpl

- Regional Setting
sintl.cpl

- Registry Editor
regedit

- Registry Editor
regedit32

- Remote Desktop
mstsc

- Removable Storagent
msmgr.msc

- Removable Storage Operator Request
sntmsoprq.msc

- Resultant Set of Policy (XP Prof)
rsop.msc

- Scanners and Camera
ssticpl.cpl

- Scheduled Tasks
control schedtasks

- Security Center
wscui.cpl

- Services
services.msc

- Shared Folder
sfsmgmt.msc

- Shuts Down Windows
shutdown

- Sounds and Audio
mmsys.cpl

- Spider Solitare Card Game
spider

- SQL Client Configuration
cliconfg

- System Configuration Editor
sysedit

- System Configuration Utility
msconfig

- System File Checker Utility (Scan Immediately)
sfc /scannow

- System File Checker Utility (Scan Once At Next Boot)
sfc /scanonce

- System File Checker Utility (Scan On Every Boot)
sfc /scanboot

- System File Checker Utility (Return to Default Setting)
sfc /revert

- System File Checker Utility (Purge File Cache)
sfc /purgecache

- System File Checker Utility (Set Cache Size to size x)
sfc /cachesize=x

- System Properties
sysdm.cpl

- Task Manager
taskmgr

- Telnet Client
telnet
- User Account Management
nusrmgr.cpl

- Utility Manager
utilman
- Windows Firewall ( tường lửa)
firewall.cpl

- Windows Magnifier
magnify

- Windows Management Infrastructure
wmimgmt.msc

- Windows System Security Tool ( công cụ bảo mật)
syskey

- Windows Update Launche
swupdmgr
- Windows XP Tour Wizard
tourstart
- Wordpad