none
You have tried to create a channel to a service that does not support .Net Framing. It is possible that you are encountering an HTTP endpoint. RRS feed

  • 问题

  • 目前我把一个wcf服务寄宿到iis中,采用了tcp绑定,使用浏览器访问时没有问题,但是在通过代码访问时出现错误:

    You have tried to create a channel to a service that does not support .Net Framing. It is possible that you are encountering an HTTP endpoint.

    服务端配置:

    <?xml version="1.0"?>
    <configuration>
    
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
      <system.serviceModel>
        <!--描述绑定-->
        <bindings>
          <netTcpBinding>
            <binding name="netTcpBindConfig" closeTimeout="00:30:00"
                    openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"
                    transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                    hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                    maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10"
                    maxReceivedMessageSize="2147483647">
              <readerQuotas maxDepth="2147483647"
                              maxStringContentLength="2147483647"
                              maxArrayLength="2147483647"
                              maxBytesPerRead="2147483647"
                                maxNameTableCharCount="2147483647" />
              <reliableSession ordered="true"  inactivityTimeout="00:01:00" enabled="false" />
              <security mode="None">
                <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign"></transport>
                <message clientCredentialType="Windows" />
              </security>
            </binding>
          </netTcpBinding>
        </bindings>
        <!--描述服务-->
        <services>
          <service name="Artech.DuplexServices.Services.CalculatorService" behaviorConfiguration="CalculatorServiceBehavior">
            <host>
              <baseAddresses>
                <add baseAddress="net.tcp://localhost:8090/duplex/CalculatorService.svc"/>
              </baseAddresses>
            </host>
            <endpoint address="" contract="Artech.DuplexServices.Contracts.ICalculator" binding="netTcpBinding" 
                      bindingConfiguration="netTcpBindConfig" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="CalculatorServiceBehavior">
              
              <serviceMetadata httpGetEnabled="true"/>
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="false"/>
              <dataContractSerializer maxItemsInObjectGraph="6553600"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />-->
      </system.serviceModel>
     <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
      
    </configuration>
    


    客户端配置:

    <?xml version="1.0"?>
    <configuration>
      <system.serviceModel>
        <client>
    
             <endpoint name="CalculatorService" address="net.tcp://localhost:8090/duplex/CalculatorService.svc" binding="netTcpBinding" contract="Artech.DuplexServices.Contracts.ICalculator"/>
        
        </client>
      </system.serviceModel>
    <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
    

    客户端调用代码:

     class Program
        {
            static void Main(string[] args)
            {
                InstanceContext instanceContext = new InstanceContext(new CalculateCallback());
                using (DuplexChannelFactory<ICalculator> channelFactory = new DuplexChannelFactory<ICalculator>(instanceContext, "CalculatorService"))
                {
                    ICalculator proxy = channelFactory.CreateChannel();
                    using (proxy as IDisposable)
                    {
                        proxy.Add(1, 2);
                        Console.Read();
                    }
                }
                
            }
        }




    I believe I can!

    2012年2月7日 3:03

答案

全部回复