public int WebService_Settings(System.Web.Services.Protocols.WebClientProtocol ws, string parWebServiceName) { try { ws.Url = AppDomain.CurrentDomain.GetData("URLClientPath").ToString() + "/" + parWebServiceName + ".asmx"; ws.Credentials = System.Net.CredentialCache.DefaultCredentials; } catch { if (myCallingForm != null) { System.Windows.Forms.MessageBox.Show("Web Service '" + parWebServiceName + "' URL Path '" + AppDomain.CurrentDomain.GetData("URLClientPath").ToString() + "' is Invalid.\n\nContact System Administrator.", "Web Service Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (AppDomain.CurrentDomain.GetData("TimerCloseCurrentForm") != null) { if (pvtblnCloseFormSent == false) { if (myCallingForm != null) { pvtblnCloseFormSent = true; AppDomain.CurrentDomain.SetData("FormToClose", myCallingForm); Timer tmrCloseCurrentForm = (Timer)AppDomain.CurrentDomain.GetData("TimerCloseCurrentForm"); tmrCloseCurrentForm.Enabled = true; } } } return(-1); } return(0); }
public object CreateWSObject(string objectType, string url, Dictionary <string, object> soapHeader) { object ret = null; string ns = objectType.Substring(0, objectType.LastIndexOf(".")); string classname = objectType.Substring(objectType.LastIndexOf(".") + 1); ServiceDescriptionImporter importer1 = new ServiceDescriptionImporter(); importer1.AddServiceDescription(ServiceDescription.Read(new WebClient().OpenRead(url + "?WSDL")), "", ""); CodeNamespace namespace1 = new CodeNamespace(ns); CodeCompileUnit unit1 = new CodeCompileUnit(); unit1.Namespaces.Add(namespace1); importer1.Import(namespace1, unit1); CompilerParameters parameters1 = new CompilerParameters(); parameters1.GenerateExecutable = false; parameters1.GenerateInMemory = true; parameters1.ReferencedAssemblies.Add("System.dll"); parameters1.ReferencedAssemblies.Add("System.XML.dll"); parameters1.ReferencedAssemblies.Add("System.Web.Services.dll"); parameters1.ReferencedAssemblies.Add("System.Data.dll"); CompilerResults results1 = new CSharpCodeProvider().CompileAssemblyFromDom(parameters1, new CodeCompileUnit[] { unit1 }); if (results1.Errors.HasErrors) { StringBuilder builder1 = new StringBuilder(); foreach (CompilerError error1 in results1.Errors) { builder1.Append(error1.ToString()); builder1.Append(Environment.NewLine); } throw new Exception(builder1.ToString()); } Assembly assembly = results1.CompiledAssembly; Type type1 = assembly.GetType(ns + "." + classname, true, true); ret = Activator.CreateInstance(type1); System.Web.Services.Protocols.WebClientProtocol retWs = (System.Web.Services.Protocols.WebClientProtocol)ret; retWs.Timeout = 600000; //Plus soap head if (soapHeader != null) { string soapClassName = soapHeader["ClassName"].ToString(); //start Soap head FieldInfo client = type1.GetField(soapClassName + "Value"); //Gets the client authentication object Type typeClient = assembly.GetType(ns + "." + soapClassName); //Assign a value to the validation object object clientkey = Activator.CreateInstance(typeClient); Dictionary <string, object> headerFields = soapHeader["Fields"] as Dictionary <string, object>; foreach (string key in headerFields.Keys) { typeClient.GetField(key).SetValue(clientkey, headerFields[key]); } client.SetValue(retWs, clientkey); //Set timeout 30 seconds to prevent programs such as EFP always do not come back, resulting in request blocking // (ret as System.Web.Services.Protocols.SoapHttpClientProtocol) .Timeout = 30 * 1000; // EFP is not using ws, but directly with oracle database, so temporarily canceled, so disturb the program, there is a need to come back } return(retWs); }