本文整理汇总了C#中System.Web.Services.Description.ServiceDescriptionImporter类的典型用法代码示例。如果您正苦于以下问题:C# ServiceDescriptionImporter类的具体用法?C# ServiceDescriptionImporter怎么用?C# ServiceDescriptionImporter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServiceDescriptionImporter类属于System.Web.Services.Description命名空间,在下文中一共展示了ServiceDescriptionImporter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: InvokeWebService
public static object InvokeWebService(string url, string classname, string methodname, object[] args)
{
string @namespace = "EnterpriseServerBase.WebService.DynamicWebCalling";
if ((classname == null) || (classname == ""))
{
classname = WebServiceProxy.GetWsClassName(url);
}
try
{
//获取WSDL
WebClient wc = new WebClient();
Stream stream = wc.OpenRead(url + "?WSDL");
ServiceDescription sd = ServiceDescription.Read(stream);
ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
sdi.AddServiceDescription(sd, "", "");
CodeNamespace cn = new CodeNamespace(@namespace);
//生成客户端代理类代码
CodeCompileUnit ccu = new CodeCompileUnit();
ccu.Namespaces.Add(cn);
sdi.Import(cn, ccu);
CSharpCodeProvider csc = new CSharpCodeProvider();
ICodeCompiler icc = csc.CreateCompiler();
//设定编译参数
CompilerParameters cplist = new CompilerParameters();
cplist.GenerateExecutable = false;
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");
//编译代理类
CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
if (true == cr.Errors.HasErrors)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
{
sb.Append(ce.ToString());
sb.Append(System.Environment.NewLine);
}
throw new Exception(sb.ToString());
}
//生成代理实例,并调用方法
System.Reflection.Assembly assembly = cr.CompiledAssembly;
Type t = assembly.GetType(@namespace + "." + classname, true, true);
object obj = Activator.CreateInstance(t);
System.Reflection.MethodInfo mi = t.GetMethod(methodname);
return mi.Invoke(obj, args);
}
catch (Exception ex)
{
throw new Exception(ex.InnerException.Message, new Exception(ex.InnerException.StackTrace));
}
}
开发者ID:SLSoft,项目名称:GGZBTQPT,代码行数:60,代码来源:WebServiceProxy.cs
示例2: GetWebServiceAssembly
/// <summary>
/// get an Assembly according to wsdl path.
/// </summary>
/// <param name="wsdl">wsdl path</param>
/// <param name="nameSpace">namespace</param>
/// <returns>return Assembly</returns>
public static Assembly GetWebServiceAssembly(string wsdl, string nameSpace)
{
try
{
System.Net.WebClient webClient = new System.Net.WebClient();
System.IO.Stream webStream = webClient.OpenRead(wsdl);
ServiceDescription serviceDescription = ServiceDescription.Read(webStream);
ServiceDescriptionImporter serviceDescroptImporter = new ServiceDescriptionImporter();
serviceDescroptImporter.AddServiceDescription(serviceDescription, "", "");
System.CodeDom.CodeNamespace codeNameSpace = new System.CodeDom.CodeNamespace(nameSpace);
System.CodeDom.CodeCompileUnit codeCompileUnit = new System.CodeDom.CodeCompileUnit();
codeCompileUnit.Namespaces.Add(codeNameSpace);
serviceDescroptImporter.Import(codeNameSpace, codeCompileUnit);
System.CodeDom.Compiler.CodeDomProvider codeDom = new Microsoft.CSharp.CSharpCodeProvider();
System.CodeDom.Compiler.CompilerParameters codeParameters = new System.CodeDom.Compiler.CompilerParameters();
codeParameters.GenerateExecutable = false;
codeParameters.GenerateInMemory = true;
codeParameters.ReferencedAssemblies.Add("System.dll");
codeParameters.ReferencedAssemblies.Add("System.XML.dll");
codeParameters.ReferencedAssemblies.Add("System.Web.Services.dll");
codeParameters.ReferencedAssemblies.Add("System.Data.dll");
System.CodeDom.Compiler.CompilerResults compilerResults = codeDom.CompileAssemblyFromDom(codeParameters, codeCompileUnit);
return compilerResults.CompiledAssembly;
}
catch (Exception ex)
{
throw ex;
}
}
开发者ID:Erkan-Yilmaz,项目名称:AutomationTestFramework,代码行数:41,代码来源:WSAssembly.cs
示例3: Invoke
public object Invoke(string url, string methodName, string className = "", params object[] args)
{
if (className == null || className == "")
{
className = GetClassName(url);
}
string @namespace = "ServiceBase.WebService.DynamicWebLoad." + ProcessUrl(url);
string cacheName = string.Format("{0}_{1}", @namespace, className);
Assembly assembly = null;
if (HttpContext.Current.Cache[cacheName] != null)
{
assembly = HttpContext.Current.Cache[cacheName] as Assembly;
}
else
{
//获取服务描述语言(WSDL)
WebClient wc = new WebClient();
Stream stream = wc.OpenRead(url + "?WSDL");
ServiceDescription sd = ServiceDescription.Read(stream);
ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
sdi.AddServiceDescription(sd, "", "");
CodeNamespace cn = new CodeNamespace(@namespace);
//生成客户端代理类代码
CodeCompileUnit ccu = new CodeCompileUnit();
ccu.Namespaces.Add(cn);
sdi.Import(cn, ccu);
CSharpCodeProvider csc = new CSharpCodeProvider();
ICodeCompiler icc = csc.CreateCompiler();
//设定编译器的参数
CompilerParameters cplist = new CompilerParameters();
cplist.GenerateExecutable = false;
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");
//编译代理类
CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
if (true == cr.Errors.HasErrors)
{
System.Text.StringBuilder sb = new StringBuilder();
foreach (CompilerError ce in cr.Errors)
{
sb.Append(ce.ToString());
sb.Append(System.Environment.NewLine);
}
throw new Exception(sb.ToString());
}
//生成代理实例,并调用方法
assembly = cr.CompiledAssembly;
HttpContext.Current.Cache[cacheName] = assembly;
}
Type t = assembly.GetType(@namespace + "." + className, true, true);
object obj = Activator.CreateInstance(t);
System.Reflection.MethodInfo mi = t.GetMethod(methodName);
return mi.Invoke(obj, args);
}
开发者ID:zhangweixing00,项目名称:SS.s,代码行数:60,代码来源:AgentService.asmx.cs
示例4: service_info_methods
public static void service_info_methods()
{
uri = new Uri("http://localhost:60377/Service1.asmx?wsdl");
WebRequest webRequest = WebRequest.Create(uri);
System.IO.Stream requestStream = webRequest.GetResponse().GetResponseStream();
// Get a WSDL file describing a service
ServiceDescription sd = ServiceDescription.Read(requestStream);
string sdName = sd.Services[0].Name;
// Initialize a service description servImport
ServiceDescriptionImporter servImport = new ServiceDescriptionImporter();
servImport.AddServiceDescription(sd, String.Empty, String.Empty);
servImport.ProtocolName = "Soap";
servImport.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties;
CodeNamespace nameSpace = new CodeNamespace();
CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
codeCompileUnit.Namespaces.Add(nameSpace);
// Set Warnings
ServiceDescriptionImportWarnings warnings = servImport.Import(nameSpace, codeCompileUnit);
if (warnings == 0)
{
StringWriter stringWriter = new StringWriter(System.Globalization.CultureInfo.CurrentCulture);
Microsoft.CSharp.CSharpCodeProvider prov = new Microsoft.CSharp.CSharpCodeProvider();
prov.GenerateCodeFromNamespace(nameSpace, stringWriter, new CodeGeneratorOptions());
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();
int c = 0;
foreach (MethodInfo t in methodInfo)
{
if (t.Name == "Discover")
break;
c++;
}
listurl = new string[c]; c = 0;
foreach (MethodInfo t in methodInfo)
{
if (t.Name == "Discover")
break;
listurl[c++] = t.Name;
}
}
}
开发者ID:MinaYounan-CS,项目名称:WoT-Testbed-Environment,代码行数:59,代码来源:Service+Info.cs
示例5: Compile
/// <summary>
/// This is the workhorse method of the program. Given a web service type,
/// it generates a proxy class for it, strips out any excess types, and then
/// adds a few using statments to it.
/// </summary>
/// <param name="type">The web service type</param>
/// <param name="uri">The URL for the service that will be set in the constructor</param>
private bool Compile()
{
try
{
// These next two lines do the generate the WSDL based on the web service class
ServiceDescriptionReflector reflector = new ServiceDescriptionReflector();
reflector.Reflect(m_type, m_uri);
if (reflector.ServiceDescriptions.Count > 1)
throw new Exception(string.Format("Don't know how to deal with multiple service descriptions in {0}", m_type));
// Now we take the WSDL service description and turn it into a proxy in CodeDOM form
ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
importer.AddServiceDescription(reflector.ServiceDescriptions[0], null, null);
importer.Style = m_style;
// Probably a good idea to make the namespace a command-line parameter, but hardcode it for now
//CodeNamespace codeNamespace = new CodeNamespace("Integic.ePower.Psd.WebServices.Common.Proxies");
CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
codeCompileUnit.Namespaces.Add(CodeNamespace);
ServiceDescriptionImportWarnings warnings = importer.Import(CodeNamespace, codeCompileUnit);
// TODO: explicitly handle all of the warnings generated by the ServiceImporter
if (warnings != 0)
{
Trace.TraceError("Warnings: {1}", warnings);
string errorMessage;
switch (warnings)
{
case ServiceDescriptionImportWarnings.NoMethodsGenerated:
errorMessage = string.Format("Error: Web service at {0} does not contain any web methods", m_type.FullName);
throw new ApplicationException(errorMessage);
case ServiceDescriptionImportWarnings.NoCodeGenerated:
errorMessage = string.Format("Error: No code was generated for web service at {0}", m_type.FullName);
throw new ApplicationException(errorMessage);
default:
errorMessage = string.Format("Error: Unhandled error while generating code for web service {0} : {1}", m_type.FullName, warnings.ToString());
throw new ApplicationException(errorMessage);
}
}
if (!GenerateCode())
return false;
}
catch (Exception ex)
{
Errors.Add(new CompilerError(string.Empty, 0, 0, string.Empty, ex.Message));
Trace.TraceError(ex.ToString());
return false;
}
return true;
}
开发者ID:nujmail,项目名称:xsd-to-classes,代码行数:64,代码来源:TypeProxyGenerator.cs
示例6: InvokeWebService
/// <summary>
/// 实例化WebServices
/// </summary>
/// <param name="url">WebServices地址</param>
/// <param name="methodname">调用的方法</param>
/// <param name="args">把webservices里需要的参数按顺序放到这个object[]里</param>
public static object InvokeWebService(string url, string methodname, object[] args)
{
//这里的namespace是需引用的webservices的命名空间,我没有改过,也可以使用。也可以加一个参数从外面传进来。
string @namespace = "client";
try
{
//获取WSDL
WebClient wc = new WebClient();
Stream stream = wc.OpenRead(url + "?WSDL");
ServiceDescription sd = ServiceDescription.Read(stream);
string classname = sd.Services[0].Name;
ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
sdi.AddServiceDescription(sd, "", "");
CodeNamespace cn = new CodeNamespace(@namespace);
//生成客户端代理类代码
CodeCompileUnit ccu = new CodeCompileUnit();
ccu.Namespaces.Add(cn);
sdi.Import(cn, ccu);
CSharpCodeProvider csc = new CSharpCodeProvider();
//ICodeCompiler icc = csc.CreateCompiler();
//设定编译参数
CompilerParameters cplist = new CompilerParameters();
cplist.GenerateExecutable = false;
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");
//编译代理类
CompilerResults cr = csc.CompileAssemblyFromDom(cplist, ccu);
if (true == cr.Errors.HasErrors)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
{
sb.Append(ce.ToString());
sb.Append(System.Environment.NewLine);
}
throw new Exception(sb.ToString());
}
//生成代理实例,并调用方法
System.Reflection.Assembly assembly = cr.CompiledAssembly;
Type t = assembly.GetType(@namespace + "." + classname, true, true);
object obj = Activator.CreateInstance(t);
System.Reflection.MethodInfo mi = t.GetMethod(methodname);
return mi.Invoke(obj, args);
}
catch(Exception ex)
{
return ex.Message;
}
}
开发者ID:fqybzhangji,项目名称:Crazy,代码行数:63,代码来源:1452646768$webservice.cs
示例7: GenerateCodeFromWsdl
CodeNamespace GenerateCodeFromWsdl (ServiceDescription sd)
{
ServiceDescriptionImporter imp =
new ServiceDescriptionImporter ();
imp.AddServiceDescription (sd, null, null);
CodeNamespace cns = new CodeNamespace ();
imp.Import (cns, null);
return cns;
}
开发者ID:nobled,项目名称:mono,代码行数:9,代码来源:ServiceDescriptionImporterTest.cs
示例8: Invoke
public static object Invoke(string url, string className, string methodName, object[] parameters)
{
string compileNamespace = "Dynamic.To.Call.WebService";
if ((className == null) || (className == ""))
{
className = WebServiceHelper.GetClassName(url);
}
//Get wsdl information
WebClient wc = new WebClient();
System.IO.Stream strm = wc.OpenRead(url + "?WSDL");
ServiceDescription sd = ServiceDescription.Read(strm);
ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
sdi.AddServiceDescription(sd, "", "");
CodeNamespace cn = new CodeNamespace(compileNamespace);
//Generate client proxy class
CodeCompileUnit ccu = new CodeCompileUnit();
ccu.Namespaces.Add(cn);
sdi.Import(cn, ccu);
CSharpCodeProvider csc = new CSharpCodeProvider();
ICodeCompiler icc = csc.CreateCompiler();
//Setting compile parameters
CompilerParameters compilerParams = new CompilerParameters();
compilerParams.GenerateExecutable = false;
compilerParams.GenerateInMemory = true;
compilerParams.ReferencedAssemblies.Add("System.dll");
compilerParams.ReferencedAssemblies.Add("System.XML.dll");
compilerParams.ReferencedAssemblies.Add("System.Web.Services.dll");
compilerParams.ReferencedAssemblies.Add("System.Data.dll");
//compile agentcy class
CompilerResults cr = icc.CompileAssemblyFromDom(compilerParams, ccu);
if (true == cr.Errors.HasErrors)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
{
sb.Append(ce.ToString());
sb.Append(System.Environment.NewLine);
}
throw new Exception(sb.ToString());
}
//Build agent entity & call method
System.Reflection.Assembly assembly = cr.CompiledAssembly;
Type t = assembly.GetType(string.Concat(compileNamespace, ".", className), true, true);
object obj = Activator.CreateInstance(t);
System.Reflection.MethodInfo mi = t.GetMethod(methodName);
if (parameters != null && parameters.Length > 0)
return mi.Invoke(obj, parameters);
else
//Invoke(obj, BindingFlags.Default, new MyBinder(), new Object[] { (int)32, (int)32 }, CultureInfo.CurrentCulture);//ref to msdn
return mi.Invoke(obj, BindingFlags.Default, null, null, null);
}
开发者ID:TaylorLi,项目名称:gettogether,代码行数:56,代码来源:WebServiceHelper.cs
示例9: GetWsProxyType
public static Type GetWsProxyType(string wsUrl, string classname)
{
string name = "ESBasic.WebService.DynamicWebCalling";
if ((classname == null) || (classname == ""))
{
classname = GetWsClassName(wsUrl);
}
string key = wsUrl + "@" + classname;
if (WSProxyTypeDictionary.ContainsKey(key))
{
return WSProxyTypeDictionary[key];
}
WebClient client = new WebClient();
ServiceDescription serviceDescription = ServiceDescription.Read(client.OpenRead(wsUrl + "?WSDL"));
ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
importer.AddServiceDescription(serviceDescription, "", "");
CodeNamespace namespace2 = new CodeNamespace(name);
CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
codeCompileUnit.Namespaces.Add(namespace2);
importer.Import(namespace2, codeCompileUnit);
ICodeCompiler compiler = new CSharpCodeProvider().CreateCompiler();
CompilerParameters options = new CompilerParameters
{
GenerateExecutable = false,
GenerateInMemory = true
};
options.ReferencedAssemblies.Add("System.dll");
options.ReferencedAssemblies.Add("System.XML.dll");
options.ReferencedAssemblies.Add("System.Web.Services.dll");
options.ReferencedAssemblies.Add("System.Data.dll");
CompilerResults results = compiler.CompileAssemblyFromDom(options, codeCompileUnit);
if (results.Errors.HasErrors)
{
StringBuilder builder = new StringBuilder();
foreach (CompilerError error in results.Errors)
{
builder.Append(error.ToString());
builder.Append(Environment.NewLine);
}
throw new Exception(builder.ToString());
}
Assembly compiledAssembly = results.CompiledAssembly;
compiledAssembly.GetTypes();
Type type2 = compiledAssembly.GetType(name + "." + classname, true, true);
lock (WSProxyTypeDictionary)
{
if (!WSProxyTypeDictionary.ContainsKey(key))
{
WSProxyTypeDictionary.Add(key, type2);
}
}
return type2;
}
开发者ID:JBTech,项目名称:Dot.Utility,代码行数:53,代码来源:WebServiceHelper.cs
示例10: InvokeWebServiceNew
/// <summary>
/// ��̬����WebService
/// </summary>
/// <param name="url">WebService��ַ</param>
/// <param name="classname">����</param>
/// <param name="methodname">������(ģ����)</param>
/// <param name="args">�����б�</param>
/// <returns>object</returns>
public static object InvokeWebServiceNew(string url, string classname, string methodname, object[] args)
{
string @namespace = "ServiceBase.WebService.DynamicWebLoad";
if (classname == null || classname == "")
{
classname = CallWebServise.GetClassName(url);
}
//��ȡ������������(WSDL)
WebClient wc = new WebClient();
Stream stream = wc.OpenRead(url + "?WSDL");
ServiceDescription sd = ServiceDescription.Read(stream);
ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
sdi.AddServiceDescription(sd, "", "");
CodeNamespace cn = new CodeNamespace(@namespace);
//���ɿͻ��˴������
CodeCompileUnit ccu = new CodeCompileUnit();
ccu.Namespaces.Add(cn);
sdi.Import(cn, ccu);
CSharpCodeProvider csc = new CSharpCodeProvider();
ICodeCompiler icc = csc.CreateCompiler();
//�趨�������IJ���
CompilerParameters cplist = new CompilerParameters();
cplist.GenerateExecutable = false;
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");
//���������
CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
if (true == cr.Errors.HasErrors)
{
System.Text.StringBuilder sb = new StringBuilder();
foreach (CompilerError ce in cr.Errors)
{
sb.Append(ce.ToString());
sb.Append(System.Environment.NewLine);
}
throw new Exception(sb.ToString());
}
//���ɴ���ʵ��,�����÷���
System.Reflection.Assembly assembly = cr.CompiledAssembly;
Type t = assembly.GetType(@namespace + "." + classname, true, true);
object obj = Activator.CreateInstance(t);
System.Reflection.MethodInfo mi = t.GetMethod(methodname);
return mi.Invoke(obj, args);
}
开发者ID:monkinone,项目名称:OrderPrinnt,代码行数:61,代码来源:CallWebServise.cs
示例11: BuildCodeCompileUnit
private static CodeCompileUnit BuildCodeCompileUnit(ServiceDescriptionImporter descriptionImporter)
{
var codeNamespace = new CodeNamespace();
var codeUnit = new CodeCompileUnit();
codeUnit.Namespaces.Add(codeNamespace);
var importWarnings = descriptionImporter.Import(codeNamespace, codeUnit);
if (importWarnings != 0)
throw new Exception("Invalid WSDL");
return codeUnit;
}
开发者ID:sadowskik,项目名称:WebServiceInvoker,代码行数:13,代码来源:CodeDomAssemblyComplier.cs
示例12: BuildAssembly
public Assembly BuildAssembly(ServiceDescriptionImporter descriptionImporter)
{
var codeUnit = BuildCodeCompileUnit(descriptionImporter);
var parameters = BuildCompilerParameters();
var compiler = CodeDomProvider.CreateProvider("CSharp");
var results = compiler.CompileAssemblyFromDom(parameters, codeUnit);
if (results.Errors.Cast<CompilerError>().Any())
throw new Exception("Compilation Error Creating Assembly");
return results.CompiledAssembly;
}
开发者ID:sadowskik,项目名称:WebServiceInvoker,代码行数:13,代码来源:CodeDomAssemblyComplier.cs
示例13: SoapHelper
/// <summary>
/// 动态 WebService 构造函数
/// </summary>
/// <param name="pUrl">WebService 地址</param>
/// <param name="pClassname">类名,可省略,可空</param>
public SoapHelper(string pUrl, string pClassname = null)
{
if (String.IsNullOrEmpty(pClassname))
WebServiceClassname = GetWsClassName(pUrl);
else
WebServiceClassname = pClassname;
WebServiceNamespace = "LiveAzure.Utility";
try
{
WebClient wc = new WebClient();
Stream stream = wc.OpenRead(pUrl + "?WSDL");
ServiceDescription sd = ServiceDescription.Read(stream);
ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
sdi.AddServiceDescription(sd, "", "");
sdi.ProtocolName = "Soap";
sdi.Style = ServiceDescriptionImportStyle.Client;
sdi.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties | CodeGenerationOptions.GenerateNewAsync;
CodeNamespace cn = new CodeNamespace(this.WebServiceNamespace);
SoapCompileUnit = new CodeCompileUnit();
SoapCompileUnit.Namespaces.Add(cn);
sdi.Import(cn, SoapCompileUnit);
CSharpCodeProvider csc = new CSharpCodeProvider();
SoapCodeProvider = CodeDomProvider.CreateProvider("CSharp");
CompilerParameters cparam = new CompilerParameters();
cparam.GenerateExecutable = false;
cparam.GenerateInMemory = true;
cparam.ReferencedAssemblies.Add("System.dll");
cparam.ReferencedAssemblies.Add("System.XML.dll");
cparam.ReferencedAssemblies.Add("System.Web.Services.dll");
cparam.ReferencedAssemblies.Add("System.Data.dll");
SoapCompilerResults = SoapCodeProvider.CompileAssemblyFromDom(cparam, SoapCompileUnit);
if (SoapCompilerResults.Errors.HasErrors)
{
StringBuilder sb = new StringBuilder();
foreach (CompilerError ce in SoapCompilerResults.Errors)
{
sb.Append(ce.ToString());
sb.Append(Environment.NewLine);
}
throw new Exception(sb.ToString());
}
}
catch (Exception ex)
{
throw new Exception(ex.InnerException.Message, new Exception(ex.InnerException.StackTrace));
}
}
开发者ID:NH4CL,项目名称:UniProject,代码行数:55,代码来源:SoapHelper.cs
示例14: InvokeWebService
/// <summary>
/// 动态调用WebService
/// </summary>
/// <param name="url">WebService地址</param>
/// <param name="classname">类名</param>
/// <param name="methodname">方法名(模块名)</param>
/// <param name="args">参数列表</param>
/// <returns>object</returns>
public static object InvokeWebService(string url, string classname, string methodname, object[] args)
{
string @namespace = "wangsx.test";
if (classname == null || classname == "")
{
classname = WebServiceHelper.GetClassName(url);
}
//获取服务描述语言(WSDL)
WebClient wc = new WebClient();
Stream stream = wc.OpenRead(url + "?WSDL");//【1】
ServiceDescription sd = ServiceDescription.Read(stream);//【2】
ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();//【3】
sdi.AddServiceDescription(sd, "", "");
CodeNamespace cn = new CodeNamespace(@namespace);//【4】
//生成客户端代理类代码
CodeCompileUnit ccu = new CodeCompileUnit();//【5】
ccu.Namespaces.Add(cn);
sdi.Import(cn, ccu);
CSharpCodeProvider csc = new CSharpCodeProvider();//【6】
ICodeCompiler icc = csc.CreateCompiler();//【7】
//设定编译器的参数
CompilerParameters cplist = new CompilerParameters();//【8】
cplist.GenerateExecutable = false;
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");
//编译代理类
CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);//【9】
if (true == cr.Errors.HasErrors)
{
System.Text.StringBuilder sb = new StringBuilder();
foreach (CompilerError ce in cr.Errors)
{
sb.Append(ce.ToString());
sb.Append(System.Environment.NewLine);
}
throw new System.Exception(sb.ToString());
}
//生成代理实例,并调用方法
System.Reflection.Assembly assembly = cr.CompiledAssembly;
System.Type t = assembly.GetType(@namespace + "." + classname, true, true);
object obj = System.Activator.CreateInstance(t);//【10】
System.Reflection.MethodInfo mi = t.GetMethod(methodname);//【11】
return mi.Invoke(obj, args);
}
开发者ID:xiaolin8,项目名称:AMS,代码行数:56,代码来源:WebServiceHelper.cs
示例15: Generate
public void Generate()
{
if (this.AddressType == AddressType.WebService)
{
string className = MethodHelper.GetClassName(this.Address);
//Get wsdl information
System.Net.WebClient wc = new System.Net.WebClient();
System.IO.Stream strm = wc.OpenRead(Address + "?WSDL");
ServiceDescription sd = ServiceDescription.Read(strm);
ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
sdi.AddServiceDescription(sd, "", "");
CodeNamespace cn = new CodeNamespace(this.ComileNamespace);
//Generate client proxy class
CodeCompileUnit ccu = new CodeCompileUnit();
ccu.Namespaces.Add(cn);
sdi.Import(cn, ccu);
CSharpCodeProvider csc = new CSharpCodeProvider();
ICodeCompiler icc = csc.CreateCompiler();
//Setting compile parameters
CompilerParameters compilerParams = new CompilerParameters();
compilerParams.GenerateExecutable = false;
compilerParams.GenerateInMemory = true;
compilerParams.ReferencedAssemblies.Add("System.dll");
compilerParams.ReferencedAssemblies.Add("System.XML.dll");
compilerParams.ReferencedAssemblies.Add("System.Web.Services.dll");
compilerParams.ReferencedAssemblies.Add("System.Data.dll");
//compile agentcy class
CompilerResults cr = icc.CompileAssemblyFromDom(compilerParams, ccu);
if (true == cr.Errors.HasErrors)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
{
sb.Append(ce.ToString());
sb.Append(System.Environment.NewLine);
}
throw new Exception(sb.ToString());
}
this.ProxyAssemble = cr.CompiledAssembly;
Type t = this.ProxyAssemble.GetType(string.Concat(this.ComileNamespace, ".", className), true, true);
ServiceObject = Activator.CreateInstance(t);
}
else
{
ServiceObject = new NormalRequest();
}
SetUrl(this.Address);
}
开发者ID:TaylorLi,项目名称:gettogether,代码行数:48,代码来源:Wsdl.cs
示例16: ReadServiceDescriptionImporter
/// <summary>Read the specified protocol into an ServiceDescriptionImporter.</summary>
/// <param name="protocol">A DiscoveryClientProtocol containing the service protocol detail.</param>
/// <returns>A ServiceDescriptionImporter for the specified protocol.</returns>
public static ServiceDescriptionImporter ReadServiceDescriptionImporter(DiscoveryClientProtocol protocol)
{
// Service Description Importer
ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
importer.ProtocolName = "Soap";
// Add all the schemas and service descriptions to the importer
protocol.ResolveAll ();
foreach (object doc in protocol.Documents.Values)
{
if (doc is ServiceDescription)
importer.AddServiceDescription((ServiceDescription)doc, null, null);
else if (doc is XmlSchema)
importer.Schemas.Add((XmlSchema)doc);
}
return importer;
}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:19,代码来源:Library.cs
示例17: GetTypeFromWebService
static Type GetTypeFromWebService(string url, string className)
{
string @namespace = "EnterpriseServerBase.WebService.DynamicWebCalling";
if ((className == null) || (className == ""))
{
className = GetWsClassName(url);
}
//获取WSDL
WebClient wc = new WebClient();
Stream stream = wc.OpenRead(url + "?WSDL");
ServiceDescription sd = ServiceDescription.Read(stream);
ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
sdi.AddServiceDescription(sd, "", "");
CodeNamespace cn = new CodeNamespace(@namespace);
//生成客户端代理类代码
CodeCompileUnit ccu = new CodeCompileUnit();
ccu.Namespaces.Add(cn);
sdi.Import(cn, ccu);
//CSharpCodeProvider csc = new CSharpCodeProvider();
//ICodeCompiler icc = new CSharpCodeProvider();
CSharpCodeProvider icc = new CSharpCodeProvider();
//设定编译参数
CompilerParameters cplist = new CompilerParameters();
cplist.GenerateExecutable = false;
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");
//编译代理类
CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
if (true == cr.Errors.HasErrors)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
{
sb.Append(ce.ToString());
sb.Append(System.Environment.NewLine);
}
throw new Exception(sb.ToString());
}
//生成代理实例,并调用方法
System.Reflection.Assembly assembly = cr.CompiledAssembly;
Type t = assembly.GetType(@namespace + "." + className, true, true);
return t;
}
开发者ID:shaohaiou,项目名称:comopp,代码行数:47,代码来源:DynamicWebServices.cs
示例18: InvokeWebService
public static object InvokeWebService(string url, string @namespace, string classname, string methodname, object[] args)
{
try
{
System.Net.WebClient wc = new System.Net.WebClient();
System.IO.Stream stream = wc.OpenRead(url + "?WSDL");
System.Web.Services.Description.ServiceDescription sd = System.Web.Services.Description.ServiceDescription.Read(stream);
System.Web.Services.Description.ServiceDescriptionImporter sdi = new System.Web.Services.Description.ServiceDescriptionImporter();
sdi.AddServiceDescription(sd, "", "");
System.CodeDom.CodeNamespace cn = new System.CodeDom.CodeNamespace(@namespace);
|
请发表评论