0

I have create wcf application: this contract:

namespace WcfServiceLibrary1
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);   

    }
}

this is service:

namespace WcfServiceLibrary1
{

    public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }
}
}

this is App.config

  <?xml version="1.0"?>

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength="2097151"
    useFullyQualifiedRedirectUrl="true"
    executionTimeout="144000"   />
  </system.web>
  <system.serviceModel>
    <!--<bindings>
      <basicHttpBinding>
        <binding name="FileTransferServicesBinding" transferMode="Streamed" messageEncoding="Mtom" maxReceivedMessageSize="2000000">
        </binding>
      </basicHttpBinding>
    </bindings>-->

    <bindings>
      <wsDualHttpBinding>
        <binding name="WSDualHttpBinding_IChatService" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" 
                 sendTimeout="00:03:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
                 maxBufferPoolSize="104857600" maxReceivedMessageSize="104857600" messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true">
          <readerQuotas maxDepth="104857600" maxStringContentLength="104857600" maxArrayLength="104857600" maxBytesPerRead="104857600" maxNameTableCharCount="104857600"/>
          <reliableSession ordered="true" inactivityTimeout="00:10:00"/>
          <security mode="None">
            <message clientCredentialType="None" negotiateServiceCredential="false" algorithmSuite="Default"/>
          </security>
        </binding>
      </wsDualHttpBinding>
    </bindings>
    <services>
      <!--<service behaviorConfiguration="MyServiceTypeBehaviors" name="FileService.FileTransferService">
        <endpoint address="mex" binding="basicHttpBinding" bindingConfiguration="FileTransferServicesBinding" contract="FileService.IFileTransferService"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/FileTranfer"/>
          </baseAddresses>
        </host>
      </service>-->
      <service behaviorConfiguration="MyServiceTypeBehaviors" name="WcfServiceLibrary1.Service1">
        <endpoint address="mex" binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IChatService" contract="WcfServiceLibrary1.IService1"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://117.5.36.172:23000/FileTranfer"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceTypeBehaviors">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

after add service reference at address: "http://117.5.36.172:23000/FileTranfer" I run service ok. after create :

ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();

                Console.WriteLine(client.State); ====> return Created
                Console.WriteLine(client.GetData(5)); ==>Not return value, seems 

it's not access. I opened firewall port 23000 and add forward port router. please help me thanks all

1 Answers1

0

There's a real problem with WSDualHttpBinding and the way most people are connected to the internet - being behind a router means, at least with IPv4, having NAT ruin the party, as you've already discovered.

With WSDualHttpBinding, you have two connections: From the client to the server, and from the server to the client.

Usually, the client-to-server connection isn't a big deal - that's how most communication is done over the internet. In your case, it seems that you were behind a firewall and you've opened/forwarded the needed ports. But that doesn't solve the problem of the second connection - from the server to the client. Basically what happens with that second connection is that the client acts as a server, and the server acts as a client. So you need to do the same port opening/forwarding with each and every client that connects to your service, because it also acts as a server! This is of course an unreasonable demand to make of every user of your service. That's why WSDualHttpBinding is more suited to server-to-server communications, where the setup is a one-time affair.

Instead of trying to get WSDualHttpBinding to work, I suggest you switch to NetTcpBinding. Since both WSDualHttpBinding and NetTcpBinding are WCF-only, Microsoft-only, proprietary connection schemes, you're not losing much in the way of interoperability. What you're gaining, on the other hand, is a lot:

NetTcpBinding uses only a single connection, from the client to the server, while allowing two way communication like WSDualHttpBinding. So there's no need to deal with port opening/forwarding on the client side - NAT is a non-issue. The communication protocol is binary and is more compact than the plain-text XML used in WSDualHttpBinding. Less data transfer means a better performing service. With NetTcpBinding, you can get instant notification of when a client disconnects, since a socket is closed. No need to wait for a HTTP timeout like you do with WSDualHttpBinding. A single connection means there nothing that can go out of sync - with WSDualHttpBinding, one of the two connections may drop while the other may still be active, having only one way communication. WCF has a way of dealing with that, but it's better to just avoid the issue in the first place.

Switching to NetTcpBinding usually only requires a configuration change - the code remains the same. It's simple, it's fast, it's much less of a hassle and most importantly - it just works.

thanks to Connecting over internet to WCF service using wsDualHttpBinding times out

Community
  • 1
  • 1