【发布时间】:2011-02-25 18:30:07
【问题描述】:
每次我的程序运行时,vs 都会将默认配置添加到我的 app.config 文件中。在那次运行时它运行良好,但在下一次运行时它实际上会尝试读取配置。
问题是默认配置有错误,它添加了属性“地址”,但属性不允许有大写,所以会抛出异常。
这意味着我每次运行都必须删除坏部分!
我已尝试配置 .config,但出现错误。
这是我用来托管服务器的代码:
private static System.Threading.AutoResetEvent stopFlag = new System.Threading.AutoResetEvent(false);
ServiceHost host = new ServiceHost(typeof(Service), new Uri("http://localhost:8000"));
host.AddServiceEndpoint(typeof(IService), new BasicHttpBinding(), "ChessServer");
host.Open();
stopFlag.WaitOne();
host.Close();
这是调用服务器的客户端代码:
ChannelFactory<IChessServer> scf;
scf = new ChannelFactory<IService>
(new BasicHttpBinding(), "http://localhost:8000");
IService service = scf.CreateChannel();
感谢您的帮助。
编辑:对不起,我花了这么长时间,我一直在尝试使用 DualWSHttpBinding 代替(因为我实际上需要服务器调用客户端方法)但仍然生成配置文件。这是整个自动生成的配置文件:
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Chess.ChessService">
<endpoint Address="" binding="wsHttpBinding" contract="Chess.IChessServer">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint Address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<Add baseAddress="http://localhost:8732/Design_Time_Addresses/Chess/ChessService/" />
</baseAddresses>
</host>
</service>
<service name="Chess.ChessClient">
<endpoint Address="" binding="wsHttpBinding" contract="Chess.IChessClient">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint Address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<Add baseAddress="http://localhost:8732/Design_Time_Addresses/Chess/ChessClient/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
【问题讨论】:
-
啊,是的,谢谢,在这一点上有点迷失:P