小编vir*_*rea的帖子

如何正确检测Windows,Linux和Mac操作系统

我找不到任何真正有效的方法来正确检测我的C#progrma运行的平台(Windows/Linux/Mac),特别是在返回Unix的Mac上,并且几乎不能与Linux平台区别开来!

因此,基于Mac的特性,我做了一些不太理论化,更实用的东西.

我发布了工作代码作为答案.请评论它是否适合您/可以改进.

谢谢 !

回应:

这是工作代码!

    public enum Platform
    {
        Windows,
        Linux,
        Mac
    }

    public static Platform RunningPlatform()
    {
        switch (Environment.OSVersion.Platform)
        {
            case PlatformID.Unix:
                // Well, there are chances MacOSX is reported as Unix instead of MacOSX.
                // Instead of platform check, we'll do a feature checks (Mac specific root folders)
                if (Directory.Exists("/Applications")
                    & Directory.Exists("/System")
                    & Directory.Exists("/Users")
                    & Directory.Exists("/Volumes"))
                    return Platform.Mac;
                else
                    return Platform.Linux;

            case PlatformID.MacOSX:
                return Platform.Mac;

            default:
                return Platform.Windows;
        }
    }
Run Code Online (Sandbox Code Playgroud)

c# macos mono cross-platform

19
推荐指数
2
解决办法
1万
查看次数

通过HTTPS实现C#XMLRPC.NET客户端和服务器

很难找到与https一起使用的XMLRPC.net库的信息.

可以设置"https"URL的唯一文档是:http://xml-rpc.net/faq/xmlrpcnetfaq-2-5-0.html#2.3但是它没有准确解释如何正确设置.

在下载http://xmlrpcnet.googlecode.com/files/xml-rpc.net.2.5.0.zip中提供的样本基础上试验我试过这个:

StateNameServer解决方案的client.cs文件中的更改:

IStateName svr = (IStateName)Activator.GetObject(
typeof(IStateName), "https://localhost:5678/statename.rem");
Run Code Online (Sandbox Code Playgroud)

服务器代码是什么样的

    IDictionary props = new Hashtable();
    props["name"] = "MyHttpChannel";
    props["port"] = 5678;
    HttpChannel channel = new HttpChannel(
    props,
    null,
    new XmlRpcServerFormatterSinkProvider()
    );

    ChannelServices.RegisterChannel(channel, false);

    RemotingConfiguration.RegisterWellKnownServiceType(
    typeof(StateNameServer),
    "statename.rem",
    WellKnownObjectMode.Singleton);
Run Code Online (Sandbox Code Playgroud)

当尝试使用HTTPS联系服务器时,客户端显然会丢弃异常,因为我不知道如何配置它.无论如何,有人可以帮忙吗?我应该寻找什么样的东西?

非常感谢 !

c# https remoting xml-rpc

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×2

cross-platform ×1

https ×1

macos ×1

mono ×1

remoting ×1

xml-rpc ×1