using System; using System.CodeDom; using System.CodeDom.Compiler; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Reflection; using System.Text; using System.Web.Services.Description; using System.Xml.Serialization; namespace EPB.Common { public class VedioWebService { public static object CmsServiceInstance { get; set; } public static Type CmsServiceType { get; set; } public static Assembly CmsServiceAssembly { get; set; } /// <summary> /// 初始化webservice应用 /// </summary> /// <param name="serviceUrl"></param> /// <returns></returns> public static object GetServicesResult(string serviceUrl) { #region 动态调用webservice try { // 1. 使用 WebClient 下载 WSDL 信息。 WebClient web = new WebClient(); using (Stream stream = web.OpenRead(serviceUrl)) { // 2. 创建和格式化 WSDL 文档。 ServiceDescription description = ServiceDescription.Read(stream); // 3. 创建客户端代理代理类。 ServiceDescriptionImporter importer = new ServiceDescriptionImporter(); importer.ProtocolName = "Soap"; // 指定访问协议。 importer.Style = ServiceDescriptionImportStyle.Client; // 生成客户端代理。 importer.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties | CodeGenerationOptions.GenerateNewAsync; importer.AddServiceDescription(description, null, null); // 添加 WSDL 文档。 // 4. 使用 CodeDom 编译客户端代理类。 CodeNamespace nmspace = new CodeNamespace(); // 为代理类添加命名空间,缺省为全局空间。 CodeCompileUnit unit = new CodeCompileUnit(); unit.Namespaces.Add(nmspace); ServiceDescriptionImportWarnings warning = importer.Import(nmspace, unit); CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp"); CompilerParameters parameter = new CompilerParameters(); parameter.GenerateExecutable = false; parameter.GenerateInMemory = true; parameter.ReferencedAssemblies.Add("System.dll"); parameter.ReferencedAssemblies.Add("System.XML.dll"); parameter.ReferencedAssemblies.Add("System.Web.Services.dll"); parameter.ReferencedAssemblies.Add("System.Data.dll"); CompilerResults result = provider.CompileAssemblyFromDom(parameter, unit); if (!result.Errors.HasErrors) { CmsServiceAssembly = result.CompiledAssembly; CmsServiceType = CmsServiceAssembly.GetType("CmsService"); CmsServiceInstance = Activator.CreateInstance(CmsServiceType); } } return CmsServiceInstance; } catch { return null; } #endregion } /// <summary> /// 登录(视频) /// </summary> /// <param name="serviceUrl"></param> /// <param name="sessionid"></param> /// <returns></returns> public static string InitAndUserlogin(string serviceUrl, string code) { GetServicesResult(serviceUrl); if (CmsServiceInstance != null) { MethodInfo method = CmsServiceType.GetMethod("getStreamServiceByCameraIndexCodes"); var SeeResult = method.Invoke(CmsServiceInstance, new object[] { "123", 123, code, 100001 }); LogHelper.LogDataHelper.Error("SeeResult:" + SeeResult); return SeeResult.ToString(); } return null; } } }
获取不到里面的xml
你先直接浏览器访问