在 WCF 应用程序中,我们有一个带有属性的服务契约:
namespace We.Work {
[ServiceContract(Namespace = "We", Name = "IWork", SessionMode = SessionMode.NotAllowed)]
public interface IWork
具有属性的服务合同的实现:
namespace We.Work {
[ServiceBehavior(Name = "Work", Namespace = "We",
IncludeExceptionDetailInFaults = true,
InstanceContextMode = InstanceContextMode.PerCall,
ConcurrencyMode = ConcurrencyMode.Multiple,
ReleaseServiceInstanceOnTransactionComplete = false
)]
public class WorkImplementation : IWork
服务主机(用于开发的 Windows 服务或控制台应用程序)
namespace We.Host {
// ....
workServiceHost = new ServiceHost(typeof(We.Work.WorkImplementation));
workServiceHost.Faulted += new EventHandler(Host_Faulted);
workServiceHost.Open();
最后但并非最不重要的一个 app.config:
<service behaviorConfiguration="WorkServiceBehaviour" name="We.Work.WorkImplementation">
<endpoint behaviorConfiguration="WorkEndPointBehaviour" binding="wsHttpBinding" bindingConfiguration="WorkWsHttpBindingConfig" name="WorkEndPoint" contract="We.Work.IWork"/>
<host> <baseAddresses> <add baseAddress="http://.../Work.svc"/> </baseAddresses> </host>
</service>
<behaviors>
<endpointBehaviors>
<behavior name="WorkEndPointBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="WorkServiceBehaviour">
<serviceDebug httpHelpPageEnabled="true" httpsHelpPageEnabled="true" includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceMetadata/>
<serviceThrottling maxConcurrentCalls="25" maxConcurrentSessions="25" maxConcurrentInstances="25"/>
</behavior>
</serviceBehaviors>
</behaviors>
问题:是否可以混合 app.config 和属性,哪个配置优先,什么是好的做法?
例如,ServiceContract(SessionMode = SessionMode.NotAllowed) 是否会阻止 wsHttpBinding 使用会话?
[回答:我如何确定 app.config 中的设置真的被应用了——完全限定名称有效。]