.NET Core中的System.Web.Services命名空间

贾格·辛格·西索迪亚(Jagpal Singh Sisodiya)

我正在为需要System.Web.Services名称空间的SOAP服务动态创建代理类,并且正在使用.NET 5(Core)。我无法System.Web.Services在.NET 5中找到名称空间,因此它已被弃用还是移至另一个名称空间?如何System.Web.Services在.NET 5中使用命名空间

下面是我需要此命名空间的代码:

 public class DynamicWSProxy: IDynamicWSProxy
{
    [SecurityPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]
    public object CallWebService(string webServiceAsmxUrl, string serviceName, string methodName, object[] args)
    {
        System.Net.WebClient client = new System.Net.WebClient();

        // Connect To the web service
        System.IO.Stream stream = client.OpenRead(webServiceAsmxUrl + "?wsdl");

        // Now read the WSDL file describing a service.
        ServiceDescription description = ServiceDescription.Read(stream);

        ///// LOAD THE DOM /////////

        // Initialize a service description importer.

        ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
        importer.ProtocolName = "Soap12"; // Use SOAP 1.2.
        importer.AddServiceDescription(description, null, null);

        // Generate a proxy client.
        importer.Style = ServiceDescriptionImportStyle.Client;

        // Generate properties to represent primitive values.
        importer.CodeGenerationOptions = System.Xml.Serialization.CodeGenerationOptions.GenerateProperties;

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

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

        if (warning == 0) // If zero then we are good to go
        {

            // Generate the proxy code
            CodeDomProvider provider1 = CodeDomProvider.CreateProvider("CSharp");

            // Compile the assembly proxy with the appropriate references
            string[] assemblyReferences = new string[5] { "System.dll", "System.Web.Services.dll", "System.Web.dll", "System.Xml.dll", "System.Data.dll" };

            CompilerParameters parms = new CompilerParameters(assemblyReferences);

            CompilerResults results = provider1.CompileAssemblyFromDom(parms, unit1);

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

            // Finally, Invoke the web service method

            object wsvcClass = results.CompiledAssembly.CreateInstance(serviceName, true);

            MethodInfo mi = wsvcClass.GetType().GetMethod(methodName);

            return mi.Invoke(wsvcClass, args);

        }

        else
        {
            return null;
        }
    }

}
汤玛士

System.Web.Services是WCF的前身。由于即使强大的WCF也被视为在服务器端已弃用,因此不要指望System.Web.Services在.NET Core或具体的App Model ASP.NET Core 1.0中提供该功能。它们的命名空间甚至以开头Microsoft.AspNetCore认为SOAP已过时,以支持REST和JSON。Microsoft将告诉您:使用.NET Framework,但不要使用.NET Core。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

.NET中的命名空间

来自分类Dev

为什么同时存在System.Net.Http和System.Web.Http命名空间?

来自分类Dev

为什么同时存在System.Net.Http和System.Web.Http命名空间?

来自分类Dev

如何在.Net Core中引用System.Windows命名空间?

来自分类Dev

.Net Core 框架 ASP.Net Web 应用程序的电子邮件发件人命名空间参考

来自分类Dev

命名空间System.Net为空

来自分类Dev

在Web.Config中添加命名空间

来自分类Dev

在Web.Config中添加命名空间

来自分类Dev

System.Web.Mvc命名空间和System.Web.Routing命名空间有什么区别

来自分类Dev

命名空间 System.Net.Cache 不存在

来自分类Dev

在命名空间System.Web.UI中找不到ScriptManager和UpdatePanel

来自分类Dev

在ASP.NET Core3.1中使用包含'System.Web.HttpContext'的旧项目

来自分类Dev

.NET ComboBoxItem的命名空间

来自分类Dev

在ASP.NET 5类库中找不到System.Math命名空间

来自分类Dev

.NET中System.Drawing命名空间中看不到图像类型

来自分类Dev

在.NET Core 2.2中找不到Microsoft.Extensions.EntityFrameworkCore命名空间

来自分类Dev

Roslyn VB.NET中缺少我的命名空间

来自分类Dev

在ASP.NET MVC中引用JSON的命名空间

来自分类Dev

了解Microsoft身份命名空间(System.Web.Security,Microsoft.AspNet.Identity.Core和Microsoft.AspNetCore.Identity)

来自分类Dev

在Visual Studio 2017.0中安装.Net Core 3之后,项目的默认XML命名空间必须是MSBuild XML命名空间错误。

来自分类Dev

命名空间“...”中不存在命名空间名称“...”的类型 | dotnet restore 没有帮助 | .NET C# Azure

来自分类Dev

我在哪里可以查看System.IdentityModel.Services命名空间中的源代码?

来自分类Dev

无法构建 .Net core 2.2 项目?找不到类型或命名空间名称“系统”

来自分类Dev

在MVC 5中找不到Microsoft.Web.Mvc命名空间

来自分类Dev

是否可以在Spring WS Web服务中重命名响应名称空间前缀?

来自分类Dev

是否可以在Spring WS Web服务中重命名响应名称空间前缀?

来自分类Dev

在相同解决方案错误“ System.Web.Configuration.WebConfigurationManager”中引用.NET 4.7.2项目的ASP.NET Core 3.1项目

来自分类Dev

HBase中的命名空间?

来自分类Dev

lxml中的命名空间

Related 相关文章

  1. 1

    .NET中的命名空间

  2. 2

    为什么同时存在System.Net.Http和System.Web.Http命名空间?

  3. 3

    为什么同时存在System.Net.Http和System.Web.Http命名空间?

  4. 4

    如何在.Net Core中引用System.Windows命名空间?

  5. 5

    .Net Core 框架 ASP.Net Web 应用程序的电子邮件发件人命名空间参考

  6. 6

    命名空间System.Net为空

  7. 7

    在Web.Config中添加命名空间

  8. 8

    在Web.Config中添加命名空间

  9. 9

    System.Web.Mvc命名空间和System.Web.Routing命名空间有什么区别

  10. 10

    命名空间 System.Net.Cache 不存在

  11. 11

    在命名空间System.Web.UI中找不到ScriptManager和UpdatePanel

  12. 12

    在ASP.NET Core3.1中使用包含'System.Web.HttpContext'的旧项目

  13. 13

    .NET ComboBoxItem的命名空间

  14. 14

    在ASP.NET 5类库中找不到System.Math命名空间

  15. 15

    .NET中System.Drawing命名空间中看不到图像类型

  16. 16

    在.NET Core 2.2中找不到Microsoft.Extensions.EntityFrameworkCore命名空间

  17. 17

    Roslyn VB.NET中缺少我的命名空间

  18. 18

    在ASP.NET MVC中引用JSON的命名空间

  19. 19

    了解Microsoft身份命名空间(System.Web.Security,Microsoft.AspNet.Identity.Core和Microsoft.AspNetCore.Identity)

  20. 20

    在Visual Studio 2017.0中安装.Net Core 3之后,项目的默认XML命名空间必须是MSBuild XML命名空间错误。

  21. 21

    命名空间“...”中不存在命名空间名称“...”的类型 | dotnet restore 没有帮助 | .NET C# Azure

  22. 22

    我在哪里可以查看System.IdentityModel.Services命名空间中的源代码?

  23. 23

    无法构建 .Net core 2.2 项目?找不到类型或命名空间名称“系统”

  24. 24

    在MVC 5中找不到Microsoft.Web.Mvc命名空间

  25. 25

    是否可以在Spring WS Web服务中重命名响应名称空间前缀?

  26. 26

    是否可以在Spring WS Web服务中重命名响应名称空间前缀?

  27. 27

    在相同解决方案错误“ System.Web.Configuration.WebConfigurationManager”中引用.NET 4.7.2项目的ASP.NET Core 3.1项目

  28. 28

    HBase中的命名空间?

  29. 29

    lxml中的命名空间

热门标签

归档