当我的WCF服务端用netTcpBinding绑定的时候,客户端怎么样才能添加这个服务的引用?服务品端的配置是这样的<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="Microsoft.ADC.Framework.ExceptionService.ExceptionProcess">
<endpoint address="net.tcp://127.0.0.1:8001/ExceptionService"
binding="netTcpBinding"
contract="Microsoft.ADC.Framework.ExceptionService.Contracts.IExceptionService" />
</service>
</services>
</system.serviceModel>
</configuration>
我添加服务引用的时候,输入 tcp://127.0.0.1:8001/ExceptionService 地址时,会提示出错:MetadataExchangeClient 实例无法初始化,因为方案“tcp”没有可用的绑定。可以在构造函数中提供绑定或指定 configurationName。
参数名: scheme
如果该服务已在当前解决方案中定义,请尝试生成该解决方案,然后再次添加服务引用。服务端已确定启动了,已经在监听端口了
<configuration>
<system.serviceModel>
<services>
<service name="Microsoft.ADC.Framework.ExceptionService.ExceptionProcess">
<endpoint address="net.tcp://127.0.0.1:8001/ExceptionService"
binding="netTcpBinding"
contract="Microsoft.ADC.Framework.ExceptionService.Contracts.IExceptionService" />
</service>
</services>
</system.serviceModel>
</configuration>
我添加服务引用的时候,输入 tcp://127.0.0.1:8001/ExceptionService 地址时,会提示出错:MetadataExchangeClient 实例无法初始化,因为方案“tcp”没有可用的绑定。可以在构造函数中提供绑定或指定 configurationName。
参数名: scheme
如果该服务已在当前解决方案中定义,请尝试生成该解决方案,然后再次添加服务引用。服务端已确定启动了,已经在监听端口了
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="CalculatorBehavior" name="WWB.SessionfulCalculator.Service.CalculatorService">
<endpoint address="" binding="wsHttpBinding" contract="WWB.SessionfulCalculator.Contract.ICalculator"/>
<host>
<baseAddresses >
<add baseAddress="http://localhost:9999/SessionfulCalculator"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
客户端:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="calculatorEndpointBehavior">
<clientVia viaUri="http://localhost:8080/SessionfulCalculator"/>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://localhost:9999/SessionfulCalculator" behaviorConfiguration="calculatorEndpointBehavior" binding="wsHttpBinding" contract="WWB.SessionfulCalculator.Contract.ICalculator" name="httpEndPoint"></endpoint>
</client>
</system.serviceModel>
</configuration>我的这样配好后,客户端就可以调用了
参数名: scheme
如果该服务已在当前解决方案中定义,请尝试生成该解决方案,然后再次添加服务引用。
---------------------------------------------------------------------------------
tcp没有可用的绑定,重点检查下你的配置文件,在进行添加服务引用的时候就报错了,说明你服务端的程序就说明问题了。
你用VS创建一个WcfService,让他自动生成,在生成的appconfig里有定义metaexchange endpoint和behavior的代码,copy+paste到你的appconfig里的相应位置即可。