Public Shared Function InvokeWebServices(ByVal strUrl As String, ByVal strNamespace As String, ByVal strClassNmae As String, ByVal strMethodName As String, _ ByVal args As Object()) As Object Try Dim wc As New System.Net.WebClient() Dim stream As System.IO.Stream stream = wc.OpenRead(strUrl & "?WSDL") Dim sd = System.Web.Services.Description.ServiceDescription.Read(stream) Dim sdi As New System.Web.Services.Description.ServiceDescriptionImporter sdi.AddServiceDescription(sd, "", "") Dim cn As New System.CodeDom.CodeNamespace(strNamespace) Dim ccu As New System.CodeDom.CodeCompileUnit() ccu.Namespaces.Add(cn) sdi.Import(cn, ccu) Dim vbp As New Microsoft.VisualBasic.VBCodeProvider() Dim icc As System.CodeDom.Compiler.ICodeCompiler = vbp.CreateCompiler() Dim cplist As New System.CodeDom.Compiler.CompilerParameters() cplist.GenerateInMemory = True cplist.ReferencedAssemblies.Add("System.dll") cplist.ReferencedAssemblies.Add("System.XML.dll") cplist.ReferencedAssemblies.Add("System.Web.Services.dll") cplist.ReferencedAssemblies.Add("System.Data.dll") Dim cr As System.CodeDom.Compiler.CompilerResults = icc.CompileAssemblyFromDom(cplist, ccu) If True = cr.Errors.HasErrors Then Dim sb As New System.Text.StringBuilder Dim ce As System.CodeDom.Compiler.CompilerError For Each ce In cr.Errors sb.Append(ce.ToString) sb.Append(system.Environment.NewLine) Next Throw New Exception(sb.ToString()) End If Dim assembly As System.Reflection.Assembly = cr.CompiledAssembly Dim t As Type = assembly.GetType(strNamespace & "." & strClassNmae, True, True) Dim obj As Object = Activator.CreateInstance(t) Dim mi As System.Reflection.MethodInfo = t.GetMethod(strMethodName) Return mi.Invoke(obj, args) Catch ex As Exception Throw New Exception(ex.InnerException.Message, New Exception(ex.InnerException.StackTrace)) End Try End Function
--------------------- 作者:fmideal 来源:CSDN 原文:https://blog.csdn.net/fmideal/article/details/1716448