步骤如下:
1.添加 DLR (dynamic language runtime) 配置片段;
Section 定义:
<section name="microsoft.scripting" requirePermission="false"
type="Microsoft.Scripting.Hosting.Configuration.Section, Microsoft.Scripting"/>
Section 内容:
<microsoft.scripting>
<languages>
<language extensions=".py" displayName="IronPython"
type="IronPython.Runtime.PythonContext, IronPython"
names="IronPython;Python;py"/>
</languages>
</microsoft.scripting>
2.增加 DLR 命令加载器;
<SuperSocket>
......
<commandLoaders>
<add name="dynamicCommandLoader" type="SuperSocket.Dlr.DynamicCommandLoader, SuperSocket.Dlr"/>
</commandLoaders>
</superSocket>
3.为你的服务器实例启用该命令加载器:
<servers>
<server name="IronPythonServer"
serverTypeName="IronPythonService"
ip="Any" port="2012"
maxConnectionNumber="50"
commandLoader="dynamicCommandLoader">
</server>
</servers>
完整的配置如下:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="superSocket" type="SuperSocket.SocketEngine.Configuration.SocketServiceConfig, SuperSocket.SocketEngine" />
<section name="microsoft.scripting" requirePermission="false"
type="Microsoft.Scripting.Hosting.Configuration.Section, Microsoft.Scripting"/>
</configSections>
<appSettings>
<add key="ServiceName" value="SupperSocketService" />
</appSettings>
<connectionStrings/>
<superSocket>
<servers>
<server name="IronPythonServer"
serverTypeName="IronPythonService"
ip="Any" port="2012"
maxConnectionNumber="50"
commandLoader="dynamicCommandLoader">
</server>
</servers>
<serverTypes>
<add name="IronPythonService"
type="SuperSocket.QuickStart.IronSocketServer.DynamicAppServer, SuperSocket.QuickStart.IronSocketServer" />
</serverTypes>
<commandLoaders>
<add name="dynamicCommandLoader" type="SuperSocket.Dlr.DynamicCommandLoader, SuperSocket.Dlr"/>
</commandLoaders>
</superSocket>
<microsoft.scripting>
<languages>
<language extensions=".py" displayName="IronPython"
type="IronPython.Runtime.PythonContext, IronPython"
names="IronPython;Python;py"/>
</languages>
</microsoft.scripting>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>