コード例 #1
0
        public static void CallWebService(GeneratedWebServiceInfo generatedWebServiceInfo)
        {
            var instance    = generatedWebServiceInfo.CreateInstance();
            var methodNames = generatedWebServiceInfo.MethodNames.ToList();

            var parameters   = generatedWebServiceInfo.GetInParametersOfMethod(methodNames[0]);
            var outParameter = generatedWebServiceInfo.GetOutParameterOfMethod(methodNames[0]);

            List <object> inParaValue = new List <object>();

            foreach (var parameter in parameters)
            {
                var paraInstance = Activator.CreateInstance(parameter.ParameterType);
                foreach (var property in parameter.ParameterType.GetProperties())
                {
                    property.SetValue(paraInstance, "Test");
                    //if (parameter.ParameterType == typeof(string))
                    //{
                    //    string strValue = "Test";
                    //    inParaValue.Add(strValue);
                    //}
                }
                inParaValue.Add(paraInstance);
            }

            var outputResult = generatedWebServiceInfo.InvokeMethod(instance, methodNames[0], inParaValue.ToArray());
        }
コード例 #2
0
        private static GeneratedWebServiceInfo Run(Stream wsdlStream)
        {
            ServiceDescriptionImporter importer = GetServiceDescriptionImporter(wsdlStream);

            // Initialize a Code-DOM tree into which we will import the service.
            CodeNamespace   nmspace = new CodeNamespace();
            CodeCompileUnit unit    = new CodeCompileUnit();

            unit.Namespaces.Add(nmspace);

            // Import the service into the Code-DOM tree. This creates proxy code
            // that uses the service.
            ServiceDescriptionImportWarnings warning = importer.Import(nmspace, unit);

            if (warning == 0)
            {
                CompilerResults results = GetCompilerResults(unit);

                // Check For Errors
                if (results.Errors.Count > 0)
                {
                    System.Diagnostics.Debug.WriteLine("========Compiler error============");
                    foreach (CompilerError compilerError in results.Errors)
                    {
                        System.Diagnostics.Debug.WriteLine(compilerError.ErrorText);
                    }
                    throw new Exception("Compile Error Occured calling webservice. Check Debug ouput window.");
                }

                var getFistType = results.CompiledAssembly.GetTypes();
                GeneratedWebServiceInfo generatedWebServiceInfo = new GeneratedWebServiceInfo(getFistType[0]);

                return(generatedWebServiceInfo);
                // object wsvcClass = results.CompiledAssembly.CreateInstance(serviceName);
            }
            else
            {
                // Print an error message.
                throw new Exception(warning.ToString());
            }
        }