How To Get Hardware Information (CPU ID, MainBoard Info, Hard Disk Serial, System Information , ...)
.NET/C# 2012. 3. 28. 13:49
원본 : http://www.codeproject.com/Articles/17973/How-To-Get-Hardware-Information-CPU-ID-MainBoard-I
Introduction
For numerous reasons, you may need to access system hardware information. One example is when you have created a software and you want to put a lock on that software.
One of the most efficient ways to do so is to get one of the IDs of a piece of hardware in the target machine and then plan your software so that it can just work with the computer that has the same ID. Since some hardware IDs (and not all of them) are unique, you have very simply created a lock!
Notice
In the first versions of this article, I thought that the Processor ID was unique, but some other users told me that they had tested the Processor ID in different computers and sometimes they give the same result. So you should consider this and not try to just rely on Processor ID. I suggest that you combine it with some other IDs such as Motherboard, USB Controller, Bios, CD-ROM Drive and so on.
Another example is the need to get hard disk information, its partitions, and the free space on each partition. You may also require the hardware information while working on a multimedia application when you need to have complete information about the sound device and the VGA device of the target machine. An excellent use of this application is getting information about the memory of the system and valuable information such as the device memory address, memory device and so on.
Using the Code
First of all, you have to know that the application function is using some System.Management
classes. So you need to add this line of code:
using System.Management;
To get hardware information, you need to create an object of ManagementObjectSearcher
class.
ManagementObjectSearcher searcher = new ManagementObjectSearcher(
"select * from " + Key);
The Key
on the code above, is a variable that is replaced with appropriate data. For example, to get the information of the CPU, you have to replace the Key
with Win32_Processor
. A complete list of these keys is given below:
Win32_1394Controller
Win32_1394ControllerDevice
Win32_Account
Win32_AccountSID
Win32_ACE
Win32_ActionCheck
Win32_AllocatedResource
Win32_ApplicationCommandLine
Win32_ApplicationService
Win32_AssociatedBattery
Win32_AssociatedProcessorMemory
Win32_BaseBoard
Win32_BaseService
Win32_Battery
Win32_Binary
Win32_BindImageAction
Win32_BIOS
Win32_BootConfiguration
Win32_Bus
Win32_CacheMemory
Win32_CDROMDrive
Win32_CheckCheck
Win32_CIMLogicalDeviceCIMDataFile
Win32_ClassicCOMApplicationClasses
Win32_ClassicCOMClass
Win32_ClassicCOMClassSetting
Win32_ClassicCOMClassSettings
Win32_ClassInfoAction
Win32_ClientApplicationSetting
Win32_CodecFile
Win32_COMApplication
Win32_COMApplicationClasses
Win32_COMApplicationSettings
Win32_COMClass
Win32_ComClassAutoEmulator
Win32_ComClassEmulator
Win32_CommandLineAccess
Win32_ComponentCategory
Win32_ComputerSystem
Win32_ComputerSystemProcessor
Win32_ComputerSystemProduct
Win32_COMSetting
Win32_Condition
Win32_CreateFolderAction
Win32_CurrentProbe
Win32_DCOMApplication
Win32_DCOMApplicationAccessAllowedSetting
Win32_DCOMApplicationLaunchAllowedSetting
Win32_DCOMApplicationSetting
Win32_DependentService
Win32_Desktop
Win32_DesktopMonitor
Win32_DeviceBus
Win32_DeviceMemoryAddress
Win32_DeviceSettings
Win32_Directory
Win32_DirectorySpecification
Win32_DiskDrive
Win32_DiskDriveToDiskPartition
Win32_DiskPartition
Win32_DisplayConfiguration
Win32_DisplayControllerConfiguration
Win32_DMAChannel
Win32_DriverVXD
Win32_DuplicateFileAction
Win32_Environment
Win32_EnvironmentSpecification
Win32_ExtensionInfoAction
Win32_Fan
Win32_FileSpecification
Win32_FloppyController
Win32_FloppyDrive
Win32_FontInfoAction
Win32_Group
Win32_GroupUser
Win32_HeatPipe
Win32_IDEController
Win32_IDEControllerDevice
Win32_ImplementedCategory
Win32_InfraredDevice
Win32_IniFileSpecification
Win32_InstalledSoftwareElement
Win32_IRQResource
Win32_Keyboard
Win32_LaunchCondition
Win32_LoadOrderGroup
Win32_LoadOrderGroupServiceDependencies
Win32_LoadOrderGroupServiceMembers
Win32_LogicalDisk
Win32_LogicalDiskRootDirectory
Win32_LogicalDiskToPartition
Win32_LogicalFileAccess
Win32_LogicalFileAuditing
Win32_LogicalFileGroup
Win32_LogicalFileOwner
Win32_LogicalFileSecuritySetting
Win32_LogicalMemoryConfiguration
Win32_LogicalProgramGroup
Win32_LogicalProgramGroupDirectory
Win32_LogicalProgramGroupItem
Win32_LogicalProgramGroupItemDataFile
Win32_LogicalShareAccess
Win32_LogicalShareAuditing
Win32_LogicalShareSecuritySetting
Win32_ManagedSystemElementResource
Win32_MemoryArray
Win32_MemoryArrayLocation
Win32_MemoryDevice
Win32_MemoryDeviceArray
Win32_MemoryDeviceLocation
Win32_MethodParameterClass
Win32_MIMEInfoAction
Win32_MotherboardDevice
Win32_MoveFileAction
Win32_MSIResource
Win32_NetworkAdapter
Win32_NetworkAdapterConfiguration
Win32_NetworkAdapterSetting
Win32_NetworkClient
Win32_NetworkConnection
Win32_NetworkLoginProfile
Win32_NetworkProtocol
Win32_NTEventlogFile
Win32_NTLogEvent
Win32_NTLogEventComputer
Win32_NTLogEventLog
Win32_NTLogEventUser
Win32_ODBCAttribute
Win32_ODBCDataSourceAttribute
Win32_ODBCDataSourceSpecification
Win32_ODBCDriverAttribute
Win32_ODBCDriverSoftwareElement
Win32_ODBCDriverSpecification
Win32_ODBCSourceAttribute
Win32_ODBCTranslatorSpecification
Win32_OnBoardDevice
Win32_OperatingSystem
Win32_OperatingSystemQFE
Win32_OSRecoveryConfiguration
Win32_PageFile
Win32_PageFileElementSetting
Win32_PageFileSetting
Win32_PageFileUsage
Win32_ParallelPort
Win32_Patch
Win32_PatchFile
Win32_PatchPackage
Win32_PCMCIAController
Win32_Perf
Win32_PerfRawData
Win32_PerfRawData_ASP_ActiveServerPages
Win32_PerfRawData_ASPNET_114322_ASPNETAppsv114322
Win32_PerfRawData_ASPNET_114322_ASPNETv114322
Win32_PerfRawData_ASPNET_ASPNET
Win32_PerfRawData_ASPNET_ASPNETApplications
Win32_PerfRawData_IAS_IASAccountingClients
Win32_PerfRawData_IAS_IASAccountingServer
Win32_PerfRawData_IAS_IASAuthenticationClients
Win32_PerfRawData_IAS_IASAuthenticationServer
Win32_PerfRawData_InetInfo_InternetInformationServicesGlobal
Win32_PerfRawData_MSDTC_DistributedTransactionCoordinator
Win32_PerfRawData_MSFTPSVC_FTPService
Win32_PerfRawData_MSSQLSERVER_SQLServerAccessMethods
Win32_PerfRawData_MSSQLSERVER_SQLServerBackupDevice
Win32_PerfRawData_MSSQLSERVER_SQLServerBufferManager
Win32_PerfRawData_MSSQLSERVER_SQLServerBufferPartition
Win32_PerfRawData_MSSQLSERVER_SQLServerCacheManager
Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases
Win32_PerfRawData_MSSQLSERVER_SQLServerGeneralStatistics
Win32_PerfRawData_MSSQLSERVER_SQLServerLatches
Win32_PerfRawData_MSSQLSERVER_SQLServerLocks
Win32_PerfRawData_MSSQLSERVER_SQLServerMemoryManager
Win32_PerfRawData_MSSQLSERVER_SQLServerReplicationAgents
Win32_PerfRawData_MSSQLSERVER_SQLServerReplicationDist
Win32_PerfRawData_MSSQLSERVER_SQLServerReplicationLogreader
Win32_PerfRawData_MSSQLSERVER_SQLServerReplicationMerge
Win32_PerfRawData_MSSQLSERVER_SQLServerReplicationSnapshot
Win32_PerfRawData_MSSQLSERVER_SQLServerSQLStatistics
Win32_PerfRawData_MSSQLSERVER_SQLServerUserSettable
Win32_PerfRawData_NETFramework_NETCLRExceptions
Win32_PerfRawData_NETFramework_NETCLRInterop
Win32_PerfRawData_NETFramework_NETCLRJit
Win32_PerfRawData_NETFramework_NETCLRLoading
Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads
Win32_PerfRawData_NETFramework_NETCLRMemory
Win32_PerfRawData_NETFramework_NETCLRRemoting
Win32_PerfRawData_NETFramework_NETCLRSecurity
Win32_PerfRawData_Outlook_Outlook
Win32_PerfRawData_PerfDisk_PhysicalDisk
Win32_PerfRawData_PerfNet_Browser
Win32_PerfRawData_PerfNet_Redirector
Win32_PerfRawData_PerfNet_Server
Win32_PerfRawData_PerfNet_ServerWorkQueues
Win32_PerfRawData_PerfOS_Cache
Win32_PerfRawData_PerfOS_Memory
Win32_PerfRawData_PerfOS_Objects
Win32_PerfRawData_PerfOS_PagingFile
Win32_PerfRawData_PerfOS_Processor
Win32_PerfRawData_PerfOS_System
Win32_PerfRawData_PerfProc_FullImage_Costly
Win32_PerfRawData_PerfProc_Image_Costly
Win32_PerfRawData_PerfProc_JobObject
Win32_PerfRawData_PerfProc_JobObjectDetails
Win32_PerfRawData_PerfProc_Process
Win32_PerfRawData_PerfProc_ProcessAddressSpace_Costly
Win32_PerfRawData_PerfProc_Thread
Win32_PerfRawData_PerfProc_ThreadDetails_Costly
Win32_PerfRawData_RemoteAccess_RASPort
Win32_PerfRawData_RemoteAccess_RASTotal
Win32_PerfRawData_RSVP_ACSPerRSVPService
Win32_PerfRawData_Spooler_PrintQueue
Win32_PerfRawData_TapiSrv_Telephony
Win32_PerfRawData_Tcpip_ICMP
Win32_PerfRawData_Tcpip_IP
Win32_PerfRawData_Tcpip_NBTConnection
Win32_PerfRawData_Tcpip_NetworkInterface
Win32_PerfRawData_Tcpip_TCP
Win32_PerfRawData_Tcpip_UDP
Win32_PerfRawData_W3SVC_WebService
Win32_PhysicalMemory
Win32_PhysicalMemoryArray
Win32_PhysicalMemoryLocation
Win32_PNPAllocatedResource
Win32_PnPDevice
Win32_PnPEntity
Win32_PointingDevice
Win32_PortableBattery
Win32_PortConnector
Win32_PortResource
Win32_POTSModem
Win32_POTSModemToSerialPort
Win32_PowerManagementEvent
Win32_Printer
Win32_PrinterConfiguration
Win32_PrinterController
Win32_PrinterDriverDll
Win32_PrinterSetting
Win32_PrinterShare
Win32_PrintJob
Win32_PrivilegesStatus
Win32_Process
Win32_Processor
Win32_ProcessStartup
Win32_Product
Win32_ProductCheck
Win32_ProductResource
Win32_ProductSoftwareFeatures
Win32_ProgIDSpecification
Win32_ProgramGroup
Win32_ProgramGroupContents
Win32_ProgramGroupOrItem
Win32_Property
Win32_ProtocolBinding
Win32_PublishComponentAction
Win32_QuickFixEngineering
Win32_Refrigeration
Win32_Registry
Win32_RegistryAction
Win32_RemoveFileAction
Win32_RemoveIniAction
Win32_ReserveCost
Win32_ScheduledJob
Win32_SCSIController
Win32_SCSIControllerDevice
Win32_SecurityDescriptor
Win32_SecuritySetting
Win32_SecuritySettingAccess
Win32_SecuritySettingAuditing
Win32_SecuritySettingGroup
Win32_SecuritySettingOfLogicalFile
Win32_SecuritySettingOfLogicalShare
Win32_SecuritySettingOfObject
Win32_SecuritySettingOwner
Win32_SelfRegModuleAction
Win32_SerialPort
Win32_SerialPortConfiguration
Win32_SerialPortSetting
Win32_Service
Win32_ServiceControl
Win32_ServiceSpecification
Win32_ServiceSpecificationService
Win32_SettingCheck
Win32_Share
Win32_ShareToDirectory
Win32_ShortcutAction
Win32_ShortcutFile
Win32_ShortcutSAP
Win32_SID
Win32_SMBIOSMemory
Win32_SoftwareElement
Win32_SoftwareElementAction
Win32_SoftwareElementCheck
Win32_SoftwareElementCondition
Win32_SoftwareElementResource
Win32_SoftwareFeature
Win32_SoftwareFeatureAction
Win32_SoftwareFeatureCheck
Win32_SoftwareFeatureParent
Win32_SoftwareFeatureSoftwareElements
Win32_SoundDevice
Win32_StartupCommand
Win32_SubDirectory
Win32_SystemAccount
Win32_SystemBIOS
Win32_SystemBootConfiguration
Win32_SystemDesktop
Win32_SystemDevices
Win32_SystemDriver
Win32_SystemDriverPNPEntity
Win32_SystemEnclosure
Win32_SystemLoadOrderGroups
Win32_SystemLogicalMemoryConfiguration
Win32_SystemMemoryResource
Win32_SystemNetworkConnections
Win32_SystemOperatingSystem
Win32_SystemPartitions
Win32_SystemProcesses
Win32_SystemProgramGroups
Win32_SystemResources
Win32_SystemServices
Win32_SystemSetting
Win32_SystemSlot
Win32_SystemSystemDriver
Win32_SystemTimeZone
Win32_SystemUsers
Win32_TapeDrive
Win32_TemperatureProbe
Win32_Thread
Win32_TimeZone
Win32_Trustee
Win32_TypeLibraryAction
Win32_UninterruptiblePowerSupply
Win32_USBController
Win32_USBControllerDevice
Win32_UserAccount
Win32_UserDesktop
Win32_VideoConfiguration
Win32_VideoController
Win32_VideoSettings
Win32_VoltageProbe
Win32_WMIElementSetting
Win32_WMISetting
First, call the Get()
method of the ManagementObjectSearcher
object that this application calls the searcher
object. This will fill the object with the information you need. After that, you need to process the data that is in the searcher
object.
foreach (ManagementObject share in searcher.Get())
{
// Some Codes ...
}
Each ManagementObject
has some Properties that are useful for us. Of course the Data of those properties is needed and we can process them like this:
foreach (PropertyData PC in share.Properties)
{
//some codes ...
}
The other parts of this application are nothing but working with the ListView
control and that is really easy!
License
This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)
'.NET > C#' 카테고리의 다른 글
[C#] Network Driver Check (0) | 2011.08.11 |
---|---|
[펌] Design Pattern --> C# @.@; (0) | 2009.12.24 |
[펌] System.Xml. XmlSerializer Examples (0) | 2009.08.31 |
ADHelper - An Active Directory Class (0) | 2009.08.17 |
C# - Dynamically Invoke Web Service At Runtime (0) | 2009.08.13 |
27 Responses
Joel Chinchilla - April 17, 2009
Hi, I tried to test your example with a Java Web Service, however I need to pass credentials to Web Service. How can I do it?
Neena - May 7, 2009
Can I call this code from java
crow - May 10, 2009
Not that I am aware of.
Sergio - May 14, 2009
Hi!
finally a good example on how to call WS dynamically!
I tryed your code, and got this problem:
- my WS is as follows:
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
InitializeComponent();
}
[WebMethod]
public double Sum(double num1, double num2)
{
if ( guid == “”)
return -1;
return num1 + num2;
}
}
couldn’t be as simpler as this.
When i run your code, it does in fact create an assemby whith the correct Service1 classname and the Sum method.
So everything seems to be ok.
Problem is when I invoke Sum method it sends an exception saying that “Method ‘Service1.Sum’ not found” on line :
return (T)type.InvokeMember(methodName, BindingFlags.InvokeMethod, null, obj, args);
Any clue?
thanks in advance!
shortcuts - May 18, 2009
Off-topic Help - Need a secure web proxy to get around my school firewall. Any suggestions?
Jeremy Foster - May 19, 2009
I have this implemented and working but I have run into a limitation. I can not figure out how to capture multiple returned values in the SOAP response. Do you know of a way to do this?
Sergio - May 19, 2009
Jeremy,
what do you mean with “multiple returned values in the SOAP response”. A method only returns 1 value/object. The value itself can have a collection of values/objects. Is this what you meant?
You may try to transform the returned value to XML. Use this:
public static string SerializeObjectToXML(T obj)
{
try
{
string xmlString = null;
MemoryStream memoryStream = new MemoryStream();
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(T));
string s = “”;
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
System.Runtime.Serialization.Formatters.Soap.SoapFormatter xsoap = new System.Runtime.Serialization.Formatters.Soap.SoapFormatter();
xsoap.Serialize(memoryStream, obj);
xmlString = UTF8ByteArrayToString(memoryStream.ToArray());
return xmlString;
}
catch(Exception ex)
{
ex.GetType();
return string.Empty;
}
}
public static T UnserializeObjectFromXML(string xml)
{
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(T));
MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(xml));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
return (T)xs.Deserialize(memoryStream);
}
The Serialize method uses the SoapFormatter class, and in fact serializes the returned object just like what the Webservice call does.
Izzy - May 22, 2009
Hi, Crows.
i get this webpage/artical by google.
i got one question.
if the input parameter of the method is normal types, like string, int etc, then it is ok.
right now, I got one webservie, and its input parameter of the function is like this
string
string
int
int
int
int
int
int
int
int
there is only one input parameter : TestMessage_input.
it is a type which is similiar with Struct.
I’m confused about how to forming such an input parameter in GUI???
thanks
your reply will be appreciated and helpful.
Izzy - May 22, 2009
oh,some infos are missing.they were deleted automatically.
would you mind telling me your email?
since i really have some confusions about using this.
is that ok?
Shaun - May 22, 2009
Excellent routine! I’m having a problem using this class however. When I call “return results.CompiledAssembly;” I get the following exception:
Execution permission cannot be acquired.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Security.Policy.PolicyException: Execution permission cannot be acquired.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[PolicyException: Execution permission cannot be acquired.]
System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission) +10236136
System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission) +97
[FileLoadException: Could not load file or assembly 'm2wivo6v, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Failed to grant permission to execute. (Exception from HRESULT: 0x80131418)]
System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +416
System.Reflection.Assembly.Load(AssemblyName assemblyRef, Evidence assemblySecurity) +33
System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly() +105…
I’m running this code in SharePoint 2007 on Windows Server 2008.
vikram - May 26, 2009
It’s working fine but application memory increases when web service call are made 2500 times.
Can we delete the temporary files created while compiling assembly ?
marmri - May 31, 2009
Hi,
Thank you for this great example.
I have the same problem as Sergio - May 14, 2009
Did you wirte him any suggestion? Please forward it or add it in this article for the whole aucience!
I have another question: how to do, if you have following situation:
MyWebReference.GoodbyeWorldWSService myProxy = new MyWebReference.GoodbyeWorldWSService();
MyWebReference.sayGoodbye request = new MyWebReference.sayGoodbye();
request.message = “ciao”;
myProxy.sayGoodbye(request);
I mean, you have like an object as parameter you first initialize then invoke the service method!
Please help, is urgent. Thanx a lot in advance
Jeff - June 13, 2009
Hi As I walk on the code.. i see that the reason why its throwing an exception on this line (T)type.InvokeMember(methodName, BindingFlags.InvokeMethod, null, obj, args); it is maybe because you are calling a method with complex (custom) type and not a generic type. try to have a breakpoint on that line and see the details of the “type” variable.
shail - June 27, 2009
I am using your example. But its giving me an error on InvokeMember that “The request failed with HTTP status 401: Access Denied” Is there anything special, i will have to do here?
Thanks,
Shail …
RadoColo - June 30, 2009
Beautiful, works like a charm!
usmanbinasif - July 6, 2009
Dear it is awesome code example of this problem domain, and it is very helpful for me.
Thanks for sharing such a wonderful peice of code.
Regards,
Usman Javed
newbieDotNET - July 7, 2009
Will it be possible to invoke or set the timeout property? Any help would be greatly appreciated.
Thanks,
Jon
David Roys - July 8, 2009
What an awesome example. Well explained and a great download! Thank you for your time and effort. Unfortunately it doesn’t quite work for me.
I am also having the problem with authentication that shail posted. I know that when I use my web service by generating the proxy class, I need to use the line:
ws.UseDefaultCredentials = true in order to be able to user the service.
I am getting the following error:
Unable To Load Service: The remote server returned an error: (401) Unauthorized.
when I click the Load Service button and I can only assume it is because the XMLTextReader is not negotiating my credentials. If I use Internet explorer to hit the URL it will give me the WSDL but I believe this is because it handles the challenge response correctly. Do I need to use another method of getting my WSDL - i.e. not using XMLTextReader?
Thanks again for such a great post! I learnt a lot.
Mark - July 8, 2009
Good work, excellent explanation.
functions that expect strings do work, but functions that expect other types (int, byte[], …) do not work.
Any idea how to solve this?
Thanks
Mark
David Roys - July 10, 2009
Hi there, OK, I thought I would let other readers know that I managed to sort out my problems with authentication.
You can read the details on a blog post I made http://www.teachmenav.com/blogs/dave/archive/2009/07/11/using-reflection-to-call-nav-2009-web-services.aspx
Thanks again for the great post.
Crows Programming » I’m Back - July 15, 2009
[...] Hey guys, sorry I’ve been away for a bit. I’ll try and respond to your questions, especially those over on the C# dynamic web service page. [...]
MaTZ - July 22, 2009
Hi,
I have a problem with http authentication.
I managed to download WSDL by modifying BuildAssemblyFromWSDL like this:
System.Net.WebClient client = new System.Net.WebClient();
if (login.Length > 0)
{
client.Credentials = new NetworkCredential(login, password);
}
System.IO.Stream stream = client.OpenRead(webServiceUri.ToString() + “?wsdl”);
XmlTextReader xmlreader = new XmlTextReader(stream);
ServiceDescriptionImporter descriptionImporter = BuildServiceDescriptionImporter(xmlreader);
return CompileAssembly(descriptionImporter);
Now I’m getting exception (error 401) later when I try to invoke web method. Any ideas?
Thanks for the post.
facebook proxy - July 25, 2009
Interesting article. Were did you got all the information from…
proxies - July 25, 2009
You are a very smart person!
Andrew Brown - August 4, 2009
Very useful post. I have been using this technique for over a year.
I am having a problem where the web service request takes longer than 110 seconds to return a response. This causes a timeout error. I have been troubleshooting the timeout issue by changing all configurable timeout settings from the application setting (web.config) and IIS.
[Error Details]
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.Net.WebException: The operation has timed out.
I setup a simple test where the web server thread sleeps for 2 mins and 30 seconds.
Please post if anyone has solved this.
Donald Drake - August 5, 2009
““Method ‘Service1.Sum’ not found” ”
I was able to fix this error by using the following instead.
MethodInfo method = type.GetMethod(methodName);
return (T) method.Invoke(instance, args);
I believe the issue is due to the fact that it is using BindingFlags.InvokeMethod.. I was not able to use any other bindingflag with the type.InvokeMember method.
Hope this helps.
Thanks,
Don
Andrew Brown - August 5, 2009
I found a solution to the Timeout issue. I had to set the Timeout property of the proxy instance.
[CODE]
PropertyInfo propInfo = obj.GetType().GetProperty(”Timeout”);
propInfo.SetValue(obj, 300000 /* set this to whatever timeout period you want */, null);
Then invoke the method.