我有一个简单的 Windows 控制台应用程序,我尝试连接到 WCF 服务。我在使用以下代码时遇到问题。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartupObject>ConsoleApp_net7.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ServiceModel.Primitives" Version="6.2.0" />
</ItemGroup>
</Project>
有简单的代码:
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.ServiceModel;
using System.Xml.Serialization;
namespace ConsoleApp_net7
{
internal class Program
{
private static string serviceUrl = "http://10.240.58.103/iProfits2.GatewayServiceVERSIONING/ProfitsGateway.asmx";
static void Main(string[] args)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Windows-specific code.
var _channel = new ChannelFactory<IProfitsGateway>(serviceUrl);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
// Linux-specific code
}
//_getaway = new ProfitsGatewayUserLogin(serviceUrl);
Console.WriteLine("Hello, World!");
}
}
[ServiceContract(Namespace = "iProfits")]
[XmlSerializerFormat]
public interface IProfitsGateway
{
[OperationContract(Action = "iProfits/UserInformations", ReplyAction = "*")]
UserInformationsExport UserInformations(UserInformationsImport import, ExecutionParameters executionParameters);
}
}
当我点击 ChannelFactory 时,我得到了异常:
系统.PlatformNotSupportedException
H结果=0x80131539
Message=此平台不支持操作。
来源=System.ServiceModel.Primitives
堆栈跟踪:
在System.ServiceModel.ChannelFactory.InitializeEndpoint(字符串配置名称,EndpointAddress地址)
在 System.ServiceModel.ChannelFactory'1..ctor(字符串端点配置名称,端点地址远程地址)
在 System.ServiceModel.ChannelFactory'1..ctor(字符串端点配置名称)
在 C:\ProjectsNC\Inhouse .NET Projects\IntrasoftLogin\Test\ConsoleApp_net7\Program.cs 中的 ConsoleApp_net7.Program.Main(String[] args):第 19 行