110,568
社区成员
发帖
与我相关
我的任务
分享
private void Form1_Load(object sender, EventArgs e)
{
host = new ServiceHost(typeof(WcfServiceLibrary1.Service1));
host.Open();//启动服务
}
//想在此应用程序中直接调用服务内容
private void button1_Click(object sender, EventArgs e)
{
ChannelFactory<WcfServiceLibrary1.IService1> channel = new ChannelFactory<WcfServiceLibrary1.IService1>(new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:12345/wcfservice"));
client = channel.CreateChannel();
client.GetData(0);//执行到这里就卡住了。错误在下面
}
//该应用程序的app配置文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="WcfServiceLibrary1.Service1Behavior"
name="WcfServiceLibrary1.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="NewBinding0"
contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:12345/wcfservice/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceLibrary1.Service1Behavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="NewBinding0" portSharingEnabled="false">
<!--<security mode="None" />-->
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>