本机有WCF服务,现在需要其他电脑访问本机的wcf服务,但不使用iis,使用其他的,有没有好一点的方法?
WCF的宿主可以不是iis,随笔写一个控制台程序或winform程序都可以
使用winform宿主的话,就可以其他电脑访问本机的wcf服务了吗?如果是这样,也还是和iis一样使用添加服务引用吗,那那个地址是啥呀?
@等等小九吧717: 客户端调用改怎么调用还怎么调用,和宿主是什么没关系
寄宿到widows服务即可
可以参考:《插件式架构实现批量服务寄宿》
在Host宿主的配置文件,添加endpoint和操作契约
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="tcpBinding">
<security mode="None">
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<!--添加服务-->
<!--B服务-->
<service name="Plugins.BService.WcfService.BusinessBService" behaviorConfiguration="Plugins.BService.WcfService">
<!--name 必须与代码中的host实例初始化的服务一样 behaviorConfiguration 行为配置 -->
<host>
<baseAddresses>
<!--添加调用服务地址-->
<add baseAddress="net.tcp://172.16.0.194:3721/Plugins.BService.WcfService"/>
</baseAddresses>
</host>
<!--添加契约接口 -->
<endpoint address="net.tcp://172.16.0.194:3721/Plugins.BService.WcfService" binding="netTcpBinding" contract="Plugins.BService.WcfService.IBusinessBService" bindingConfiguration="tcpBinding" name="Plugins.BService.WcfService.BusinessBasicInfoService"></endpoint>
<endpoint address="mex" binding="mexTcpBinding" name="MEX" contract="IMetadataExchange"/>
</service>
<!--A服务-->
<service name="Plugins.AService.WcfService.BusinessAService" behaviorConfiguration="Plugins.AService.WcfService">
<!--name 必须与代码中的host实例初始化的服务一样 behaviorConfiguration 行为配置 -->
<host>
<baseAddresses>
<!--添加调用服务地址-->
<add baseAddress="net.tcp://172.16.0.194:3722/Plugins.AService.WcfService"/>
</baseAddresses>
</host>
<!--添加契约接口 -->
<endpoint address="net.tcp://172.16.0.194:3722/Plugins.AService.WcfService" binding="netTcpBinding" contract="Plugins.AService.WcfService.IBusinessAService" bindingConfiguration="tcpBinding" name="Plugins.AService.WcfService.BusinessBasicInfoService"></endpoint>
<endpoint address="mex" binding="mexTcpBinding" name="MEX" contract="IMetadataExchange"/>
</service>
<!--Resource.Robot服务-->
<service name="ResourceRobot.White.WcfService.WhiteListService" behaviorConfiguration="ResourceRobot.White.WcfService">
<!--name 必须与代码中的host实例初始化的服务一样 behaviorConfiguration 行为配置 -->
<host>
<baseAddresses>
<!--添加调用服务地址-->
<add baseAddress="net.tcp://172.16.0.194:3723/ResourceRobot.White.WcfService"/>
</baseAddresses>
</host>
<!--添加契约接口 -->
<endpoint address="net.tcp://172.16.0.194:3723/ResourceRobot.White.WcfService" binding="netTcpBinding" contract="ResourceRobot.Channels.IWhiteListService" bindingConfiguration="tcpBinding" name="ResourceRobot.White.WcfService.WhiteListService"></endpoint>
<endpoint address="mex" binding="mexTcpBinding" name="MEX" contract="IMetadataExchange"/>
</service>
</services>
<!--定义WcfServiceBehavior的行为-->
<behaviors>
<serviceBehaviors>
<behavior name="Plugins.BService.WcfService">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
<behavior name="Plugins.AService.WcfService">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
<behavior name="ResourceRobot.White.WcfService">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Windows服务上
已经解决了
使用其他宿主形式就可以了,比如控制台为基础的host