gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 21:14:53 34 4
gpt4 key购买 nike

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

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

 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。

关于.net-core - .NET Core中的System.Web.Services命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36544471/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com