首页 新闻 会员 周边

我做了一个WCF测试程序,用控制台作为宿主,服务有2个协议(http,tcp),客户端用tcp可以连接,http方式无

0
悬赏园豆:5 [待解决问题]

如题,我用http方式,在同一台机器(服务端运行的机器)上,客户端可以用http连接,换一台客户端用http的方式就不能连接了,但用tcp的方式又可以连接上来。难道是WCF 用Http协议就必须架设在IIS上才行吗?

我服务端的配置文件内容如下:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <!--<bindings>
      <netTcpBinding>
        <binding name="netTcpBinding_IService1">
          <security mode="None" />
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://192.168.0.158:8090/WcfServiceLibrary1/Service1"
                binding="netTcpBinding"
                bindingConfiguration="netTcpBinding_IService1"
                contract="ServiceReference1.IService1"
                name="netTcpBinding_IService1" />
    </client>-->

    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_IService1" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
          hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
          maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
            enabled="false" />
          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IService1" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
          textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
            enabled="false" />
          <security mode="None">
            <transport clientCredentialType="Windows" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="Windows" negotiateServiceCredential="true" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <!--<endpoint address="net.tcp://192.168.0.158:8090/WcfServiceLibrary1/Service1"
        binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IService1"
        contract="ServiceReference1.IService1" name="NetTcpBinding_IService1" />-->
      <endpoint address="http://192.168.0.158:8080/WcfServiceLibrary1/Service1"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
        contract="ServiceReference1.IService1" name="WSHttpBinding_IService1" />
    </client>

  </system.serviceModel>
</configuration>

客户端的配置文件如下:

 

<?xml version="1.0"?>
<configuration>

  <system.serviceModel>
    <services>
      <service name="WcfServiceLibrary1.Service1">

        <host>
          <baseAddresses>
            <add baseAddress="http://192.168.0.158:8088/WcfServiceLibrary1/Service1"/>
            <add baseAddress="net.tcp://192.168.0.158:8090/WcfServiceLibrary1/Service1"/>
          </baseAddresses>
        </host>



        <endpoint address="net.tcp://192.168.0.158:8090/WcfServiceLibrary1/Service1" bindingConfiguration="trans_tcp" binding="netTcpBinding" contract="WcfServiceLibrary1.IService1">
        </endpoint>

        <endpoint address="http://192.168.0.158:8088/WcfServiceLibrary1/Service1" bindingConfiguration="trans_http" binding="wsHttpBinding" contract="WcfServiceLibrary1.IService1">
        </endpoint>

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>



    <bindings>
      <netTcpBinding>
        <binding name="trans_tcp" transactionFlow="true">
          <security mode="None"></security>
        </binding>
      </netTcpBinding>

      <wsHttpBinding>
        <binding name="trans_http" transactionFlow="true">
          <security mode="None"></security>

        </binding>

      </wsHttpBinding>

    </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 为避免泄漏元数据信息,
          请在部署前将以下值设置为 false 并删除上面的元数据终结点  -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- 要接收故障异常详细信息以进行调试,
          请将以下值设置为 true。在部署前设置为 false 
            以避免泄漏异常信息-->
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

我在客户端 用telnet 测试 http 的端口,无法连接,但在同一台机器上用telnet 可以连接上

yangxq5858的主页 yangxq5858 | 初学一级 | 园豆:179
提问于:2012-11-21 10:48
< >
分享
所有回答(2)
0

看一哈防火墙的问题 或者是 IP址址或端口问题、、

在 水 一 方 | 园豆:1097 (小虾三级) | 2012-11-21 17:14
0

你的配置文件中,http服务端用的8080端口,客户端用8088端口

heqichang | 园豆:275 (菜鸟二级) | 2012-11-21 19:00

端口,我改过的。

支持(0) 反对(0) yangxq5858 | 园豆:179 (初学一级) | 2012-11-22 19:57

@yangxq5858: 那本机连可以,换台机器连不可以的话,就查看下IP是否对了,服务端防火墙是否把你的端口给屏蔽了,另外,使用http绑定也肯定能寄宿在Console下的.

支持(0) 反对(0) heqichang | 园豆:275 (菜鸟二级) | 2012-11-23 09:53

@heqichang: 能否发一个console的http方式例程给我,QQ:7313787@qq.com

支持(0) 反对(0) yangxq5858 | 园豆:179 (初学一级) | 2012-11-26 10:43
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册