Ask a questionAsk a question
 

AnswerWCF beginner. Which bindings to use?

  • Wednesday, November 04, 2009 5:01 AMdeliciousCode Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello there.

    I've written an exe for work which runs on our clients pc's in their own environment. Currently we are using .Net Remoting to communicate with the exe's, but we are having issues with firewalls/NAT blocking the communication. Starting to convert to WCF but trying to understand what binding to use. So far I've tested with wsDualHttpBinding, and it works on some machines, and not on others (both in and outsite my LAN). I'm hosting it in IIS.

    So my question is, what binding/s should I use? Needs to be able to push data through firewall/NAT.

    I'll post my current configuration if wsDualHttpBinding is the way to go and I need to configure it properly. For the sake of security, I have replaced my URL's with "example.com"

    WEB.CONFIG

    <?xml version="1.0" encoding="UTF-8"?>

    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
      <system.serviceModel>
        <services>
          <!-- Before deployment, you should remove the returnFaults behavior configuration to avoid disclosing information in exception messages -->
          <service name="ListPublishSubscribe.Service.PubSubService" behaviorConfiguration="returnFaults">
              <host>
                  <baseAddresses>
                      <add baseAddress="http://test.example.com" />
                  </baseAddresses>
              </host>
              <endpoint contract="ListPublishSubscribe.Service.IPubSubService" binding="wsDualHttpBinding" bindingConfiguration="noSecurity" />
              <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="returnFaults">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      <bindings>
      <wsDualHttpBinding>
        <binding name="noSecurity">
          <security mode="None"></security>
            <reliableSession ordered="true" inactivityTimeout="10:00:00" />
        </binding>
      </wsDualHttpBinding>
    </bindings>
      </system.serviceModel>



      <system.web>
        <compilation debug="true" />
        <customErrors mode="Off"/>
      </system.web>
        <system.webServer>
            <directoryBrowse enabled="true" />
        </system.webServer>
        <system.diagnostics>
            <switches>
                <add name="General" value="4" />
            </switches>
            <trace autoflush="true" indentsize="2">
                <listeners>
                    <add name="myListener"
                         type="System.Diagnostics.TextWriterTraceListener, Version, Culture, PublicKeyToken"
                         initializeData="MyListener.log"/>
                </listeners>
            </trace>
        </system.diagnostics>

    </configuration>





    CLIENT CONFIG

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <system.serviceModel>
            <bindings>
                <wsDualHttpBinding>
                   
                    <binding name="noSecurity">
                        <security mode="None"></security>
                        <reliableSession ordered="true" inactivityTimeout="10:00:00" />
                    </binding>
                </wsDualHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://test.example.com/PubSubService/service.svc" binding="wsDualHttpBinding" name="WSDualHttpBinding_IPubSubService" bindingConfiguration="noSecurity" contract="PubSubClient.PubSubService.IPubSubService" />
            </client>
        </system.serviceModel>
    </configuration>



    I've gotten rid of the security because our client's have static IP's so I'm adding security in later by stopping any requests that don't match our client IP list.

    IF wsDualHttpBinding is the wayto go, given the config files, can anyone explain why some machines (regardless of LAN or WAN) timeout when starting the client.exe? I'm talking about sending very small amount of data and 1 minute later it gives me a .net framework error saying it timed out.

    "The open operation did not complete within the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout."



    Thanks for your help

Answers

  • Monday, November 09, 2009 6:48 AMBin-ze ZhaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

    This probably due to to firewall protection on your client machine, you need to ensuring the clientBaseAddress port is openning on the client machine's firewall.

    When running the client in a cross-machine configuration, be sure to replace localhost in both the address attribute of the endpoint element and the clientBaseAddress attribute of the binding element of the wsDualHttpBinding element with the name of the appropriate machine, as shown:

    <client>
        <endpoint name = ""
          address=
         "http://service_machine_name/servicemodelsamples/service.svc"
        />
    </client>
    ...
    <wsDualHttpBinding>
        <binding name="DuplexBinding" clientBaseAddress=
            "http://client_machine_name:8000/myClient/">
        </binding>
    </wsDualHttpBinding>

    See reference here: http://msdn.microsoft.com/en-us/library/ms751522.aspx

    Thanks
    Binze
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

All Replies

  • Monday, November 09, 2009 6:48 AMBin-ze ZhaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

    This probably due to to firewall protection on your client machine, you need to ensuring the clientBaseAddress port is openning on the client machine's firewall.

    When running the client in a cross-machine configuration, be sure to replace localhost in both the address attribute of the endpoint element and the clientBaseAddress attribute of the binding element of the wsDualHttpBinding element with the name of the appropriate machine, as shown:

    <client>
        <endpoint name = ""
          address=
         "http://service_machine_name/servicemodelsamples/service.svc"
        />
    </client>
    ...
    <wsDualHttpBinding>
        <binding name="DuplexBinding" clientBaseAddress=
            "http://client_machine_name:8000/myClient/">
        </binding>
    </wsDualHttpBinding>

    See reference here: http://msdn.microsoft.com/en-us/library/ms751522.aspx

    Thanks
    Binze
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Thursday, November 12, 2009 3:21 AMBin-ze ZhaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Did you try my suggestion? Is it working or still not sorted?

    Please let us know what problem you facing at the moment. The port 8000 is not opened by default, you can use 80 port on your client side or manually open 8000 port through "Allow a program through windows firewall" in control pannel's windows firewall setting.

    Thanks
    Binze
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Thursday, November 12, 2009 5:35 AMdeliciousCode Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi.

    Thanks for taking the time to see if it worked.

    Unfortunately it's still not working. I was in the middle of replying but had a few ideas and never got back to replying. Can't remember the exact error it gave, but it was something along the lines of Windows not allowing me to host a connection on the clients end (eg, creating the second channel).

     I've been doing alot of reading, and so far what I can gather is that wsDualHttpBinding isn't the best way, but to use tcp binding. Still haven't been able to get THAT to work either. Kinda starting to doubt that it does in fact work as well as what it's in theory suppose to.

    I got this working perfectly. No matter the environment.
    http://msdn.microsoft.com/en-us/library/aa478452.aspx

    However, it's sockets. Not WCF. Which means I can't call methods, I can only send bytes through the channel. :(

    I think I need to start from scratch.

    Do you know if a good demo/tutorial/article on creating a wcf project that can handle callbacks over the internet without any drama's with firewalls/NAT? All I see in google is purple links.

    Thanks. :)

  • Thursday, November 12, 2009 5:51 AMBin-ze ZhaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi,

    There is one sample In the link I provided in my first post, you can download form that MSDN site and give it a test based on the scenario I mentioned.

    Thanks
    Binze


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Thursday, November 12, 2009 5:53 AMdeliciousCode Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Oh, for the record, I'm trying to develop it in .Net 3.0 with VS2005 on a Windows Server 2003 Machine...which obviously means IIS6. I mention that because I want to host it in IIS, and apparently, IIS6 doesn't support TCP stuff. Regardless though, my tests with TCP so far have all been with a console app.

    Testing procedure is as follows.
    1. Server and client both on same machine
    2. Client on different machine in LAN environment
    3. Client on different machine in LAN environment but using External IP address (port/s forwarded on router appropriately).
    4. Client on machines in 3 completely separate environments (using pcAnywhere to connect to client and run exe).
    5. Client on Vodafone Data Card.
    You probably didn't need to know that but I mentioned it to show that it has to work regardless of router/firewall/NAT.

    If only I could implement the sockets and the WCF into one thing....