应用场景描述:
我的WCF架构总体是这个样子的:
WCFHost:这个是WCF服务寄宿 及ServiceHost(控制台程序)
WCFService:这个是契约层(接口)WCFService中有多个ISayService,IWCFService
WCFBLL:这个是业务逻辑层 是实现WCFService接口的项目 多个实现以上接口的类
现在的解决方案:
服务端:使用了WCF配置文件App.config的方式来设置WCF服务信息 一下是App.config的详细配置
代码
<
system.serviceModel
>
<!-- 定义service和Endpiont行为 -->
< behaviors >
<!-- 定义service的行为 -->
< serviceBehaviors >
< behavior name = " MyServiceBehavior " >
< serviceMetadata httpGetEnabled = " true " httpGetUrl = " http://192.168.0.28:8081/mex " />
< serviceDebug includeExceptionDetailInFaults = " false " />
< serviceCredentials >
< clientCertificate >
< authentication certificateValidationMode = " Custom " customCertificateValidatorType = " WCFHost.CustomX509CertificateValidator,WCFHost " />
</ clientCertificate >
< serviceCertificate findValue = " YSTXServer " storeLocation = " CurrentUser " x509FindType = " FindBySubjectName " />
</ serviceCredentials >
</ behavior >
</ serviceBehaviors >
</ behaviors >
< bindings >
< wsHttpBinding >
< binding name = " NewBinding0 " >
< security mode = " Message " >
< message clientCredentialType = " Certificate " />
</ security >
</ binding >
</ wsHttpBinding >
</ bindings >
< services >
<!-- Service1 -->
< service behaviorConfiguration = " MyServiceBehavior " name = " BLL.MyService " >
< endpoint address = " MyService " binding = " wsHttpBinding " contract = " WCFService.IMyService " bindingConfiguration = " NewBinding0 " />
< host >
< baseAddresses >
< add baseAddress = " http://192.168.0.28:8081 " />
</ baseAddresses >
</ host >
</ service >
<!-- Service2 -->
< service behaviorConfiguration = " MyServiceBehavior " name = " BLL.ServiceSay " >
< endpoint address = " SayService " binding = " wsHttpBinding " contract = " WCFService.IService " bindingConfiguration = " NewBinding0 " ></ endpoint >
</ service >
</ services >
</ system.serviceModel >
<!-- 定义service和Endpiont行为 -->
< behaviors >
<!-- 定义service的行为 -->
< serviceBehaviors >
< behavior name = " MyServiceBehavior " >
< serviceMetadata httpGetEnabled = " true " httpGetUrl = " http://192.168.0.28:8081/mex " />
< serviceDebug includeExceptionDetailInFaults = " false " />
< serviceCredentials >
< clientCertificate >
< authentication certificateValidationMode = " Custom " customCertificateValidatorType = " WCFHost.CustomX509CertificateValidator,WCFHost " />
</ clientCertificate >
< serviceCertificate findValue = " YSTXServer " storeLocation = " CurrentUser " x509FindType = " FindBySubjectName " />
</ serviceCredentials >
</ behavior >
</ serviceBehaviors >
</ behaviors >
< bindings >
< wsHttpBinding >
< binding name = " NewBinding0 " >
< security mode = " Message " >
< message clientCredentialType = " Certificate " />
</ security >
</ binding >
</ wsHttpBinding >
</ bindings >
< services >
<!-- Service1 -->
< service behaviorConfiguration = " MyServiceBehavior " name = " BLL.MyService " >
< endpoint address = " MyService " binding = " wsHttpBinding " contract = " WCFService.IMyService " bindingConfiguration = " NewBinding0 " />
< host >
< baseAddresses >
< add baseAddress = " http://192.168.0.28:8081 " />
</ baseAddresses >
</ host >
</ service >
<!-- Service2 -->
< service behaviorConfiguration = " MyServiceBehavior " name = " BLL.ServiceSay " >
< endpoint address = " SayService " binding = " wsHttpBinding " contract = " WCFService.IService " bindingConfiguration = " NewBinding0 " ></ endpoint >
</ service >
</ services >
</ system.serviceModel >
问题:
如何在一个ServiceHost中把这个两个WCF服务发布,通过配置的方式/通过完全编码的方式?
希望WCF牛人,能够解惑!!
备注:一个Service下用多个 endpoint是不可以的,因为一个Service下的多个EndPoint 只是这个Service的多个调用方式和契约。不能实现多个Service的发布。