From the previous post, this is to show you how easy you can invoke method from web services. The code below is very short just 3 lines. There are only few steps, 1st create object using Object class, then call the Activator class for creating instance of service.
//Invoke Method
Object obj = Activator.CreateInstance(service);
Object response = t.Invoke(obj, param1);
return response;
Please try to code this and if you have any questions please comment here and I would be very happy to answer your questions.
Web Services Testing and Database Testing Tools working with Excel, Share and Free for Download. This web site is planed to share experience about Web Services Testing, WSDL, UDDI and SOAP and Test Script Manual and Auto Genenerate from AutoWS software.
Monday, March 14, 2011
Dynamic Invocation in Wsdl Reader Class
This is one of important code in the AutoWS program, DynamicInvocation. I use this one than hybernating. You can see sample of the class and function below.
WsdlReader class:
DynamicInvocation
StringWriter stringWriter = new StringWriter(System.Globalization.CultureInfo.CurrentCulture);
Microsoft.CSharp.CSharpCodeProvider prov = new Microsoft.CSharp.CSharpCodeProvider();
prov.GenerateCodeFromNamespace(nameSpace, stringWriter, new CodeGeneratorOptions());
// Compile the assembly with the appropriate references
string[] assemblyReferences = new string[2] { "System.Web.Services.dll", "System.Xml.dll" };
CompilerParameters param = new CompilerParameters(assemblyReferences);
param.GenerateExecutable = false;
param.GenerateInMemory = true;
param.TreatWarningsAsErrors = false;
param.WarningLevel = 4;
CompilerResults results = new CompilerResults(new TempFileCollection());
results = prov.CompileAssemblyFromDom(param, codeCompileUnit);
Assembly assembly = results.CompiledAssembly;
service = assembly.GetType(sdName);
methodInfo = service.GetMethods();
next chapter I will write sample how to use this class in the AutoWS program.
WsdlReader class:
DynamicInvocation
StringWriter stringWriter = new StringWriter(System.Globalization.CultureInfo.CurrentCulture);
Microsoft.CSharp.CSharpCodeProvider prov = new Microsoft.CSharp.CSharpCodeProvider();
prov.GenerateCodeFromNamespace(nameSpace, stringWriter, new CodeGeneratorOptions());
// Compile the assembly with the appropriate references
string[] assemblyReferences = new string[2] { "System.Web.Services.dll", "System.Xml.dll" };
CompilerParameters param = new CompilerParameters(assemblyReferences);
param.GenerateExecutable = false;
param.GenerateInMemory = true;
param.TreatWarningsAsErrors = false;
param.WarningLevel = 4;
CompilerResults results = new CompilerResults(new TempFileCollection());
results = prov.CompileAssemblyFromDom(param, codeCompileUnit);
Assembly assembly = results.CompiledAssembly;
service = assembly.GetType(sdName);
methodInfo = service.GetMethods();
next chapter I will write sample how to use this class in the AutoWS program.
Subscribe to:
Comments (Atom)