Ask a questionAsk a question
 

AnswerWeired chain of events...wsDualHttpBinding

  • Tuesday, November 03, 2009 10:59 PMJohny79 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Ok. So I finally got my project to override the Certificate athentication on the client side and override the UserName for client credential on the service side. So everything works fine locally. Weird thing is some systems works and some doesn't. Some of the system are in the domain and some not. Some systems are 64bit XP and some are just 32bit XP and Vista. So I am very puzzled as to what the ____ is going on.  But why will not work on all system? ARRRGGGHHHH!!!!!

    I have used HttpNamespaceManager to add namespaces and that doesn't work either. So I am lost at this point as to what is going on. I am using wsDualHttpBinding because I need to broadcast messages to certain clients or all clients and I need to track the list of clients connected to the Service.

    So these are the errors that I am getting:
    1. client is unable to finish the security negotiation within the configured timeout
    2. AddressAlreadyInUseException: HTTP could not register URL http://+:80/Temporary_Listen_Addresses/b8a65a80-151c-4770-8001-77a826d91272/ because TCP port 80 is being used by another application

    I am very lost as to what is going on. I have only been working with WCF and WPF for about a month now so I am still learning at the same time but have a project due at the end of this month on these two technologies.

    I am sorry for this long list of config files but I really need help.

    Here is my Web.config for IIS6.0 and WCF Service.
    Web.config
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.diagnostics>
        <sources>
          <source name="System.ServiceModel.MessageLogging" switchValue="Error,ActivityTracing">
            <listeners>
              <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                <filter type="" />
              </add>
              <add name="ServiceModelMessageLoggingListener">
                <filter type="" />
              </add>
            </listeners>
          </source>
          <source name="System.ServiceModel" switchValue="Error,ActivityTracing"
            propagateActivity="true">
            <listeners>
              <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                <filter type="" />
              </add>
              <add name="ServiceModelTraceListener">
                <filter type="" />
              </add>
            </listeners>
          </source>
        </sources>
        <sharedListeners>
          <add initializeData="c:\inetpub\wwwroot\webhost\http_web_services\web_messages.svclog"
            type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
            <filter type="" />
          </add>
          <add initializeData="c:\inetpub\wwwroot\webhost\http_web_services\web_tracelog.svclog"
            type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
            <filter type="" />
          </add>
        </sharedListeners>
      </system.diagnostics>
      <system.web>
        <compilation debug="true" />
      </system.web>
      <appSettings>
        <add key="baseAddress" value="http://localhost:8000/Web_Services/Web_Services/" />
      </appSettings>
      <!-- When deploying the service library project, the content of the config file must be added to the host's 
      app.config file. System.Configuration does not support config files for libraries. -->
      <system.serviceModel>
        <client>
          <endpoint address="" binding="mexHttpBinding" bindingConfiguration=""
            contract="IMetadataExchange" name="sb">
            <identity>
              <dns value="john" />
            </identity>
          </endpoint>
        </client>
        <diagnostics>
          <messageLogging logEntireMessage="true" logMalformedMessages="true"
            logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
        </diagnostics>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="false" />
        <services>
          <service behaviorConfiguration="Web_Services.Web_ServicesBehavior"
            name="Web_Services.Web_Services">
            <endpoint address="john" binding="wsDualHttpBinding" bindingConfiguration="WebServiceBinding"
              contract="Web_Services.IWeb_Services">
              <identity>
                <dns value="john" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
              <identity>
                <dns value="john" />
              </identity>
            </endpoint>
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:8000/Web_Services/Web_Services/" />
              </baseAddresses>
              <timeouts closeTimeout="00:10:10" openTimeout="00:10:00" />
            </host>
          </service>
        </services>
        <bindings>
          <wsDualHttpBinding>
            <binding closeTimeout="00:03:00" openTimeout="00:03:00" sendTimeout="00:03:00" receiveTimeout="00:03:00"
                     maxBufferPoolSize="100000000" maxReceivedMessageSize="100000000" bypassProxyOnLocal="false"
                     messageEncoding="Mtom" name="WebServiceBinding" transactionFlow="false" useDefaultWebProxy="false">
              <reliableSession inactivityTimeout="00:05:00"/>
              <readerQuotas maxDepth="32" maxStringContentLength="100000000" maxArrayLength="100000000"
                  maxBytesPerRead="100000000" maxNameTableCharCount="100000000" />
              <security mode="Message">
                <message clientCredentialType="UserName"/>
              </security>
            </binding>
          </wsDualHttpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior name="Web_Services.Web_ServicesBehavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
              <serviceCredentials>
                <serviceCertificate findValue="WebServicesCA" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
                <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Web_Services.UsernameValidator, App_Code"/>
              </serviceCredentials>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>
    
    app.config for WCF Service
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key="baseAddress" value="http://localhost:8000/Web_Services/Web_Services/" />
      </appSettings>
      <system.diagnostics>
        <sources>
          <source name="System.ServiceModel.MessageLogging" switchValue="Error,ActivityTracing">
            <listeners>
              <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                <filter type="" />
              </add>
              <add name="ServiceModelMessageLoggingListener">
                <filter type="" />
              </add>
            </listeners>
          </source>
          <source name="System.ServiceModel" switchValue="Error,ActivityTracing"
            propagateActivity="true">
            <listeners>
              <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                <filter type="" />
              </add>
              <add name="ServiceModelTraceListener">
                <filter type="" />
              </add>
            </listeners>
          </source>
        </sources>
        <sharedListeners>
          <add initializeData="c:\inetpub\wwwroot\webhost\http_Web_Services\web_messages.svclog"
            type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
            <filter type="" />
          </add>
          <add initializeData="c:\inetpub\wwwroot\webhost\http_Web_Services\web_tracelog.svclog"
            type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
            <filter type="" />
          </add>
        </sharedListeners>
      </system.diagnostics>
      <system.web>
        <compilation debug="true" />
      </system.web>
      <!-- When deploying the service library project, the content of the config file must be added to the host's 
      app.config file. System.Configuration does not support config files for libraries. -->
      <system.serviceModel>
        <client>
          <endpoint address="" binding="mexHttpBinding" bindingConfiguration=""
            contract="IMetadataExchange" name="sb">
            <identity>
              <dns value="john" />
            </identity>
          </endpoint>
        </client>
        <diagnostics>
          <messageLogging logEntireMessage="true" logMalformedMessages="true"
            logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
        </diagnostics>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="false" />
        <services>
          <service behaviorConfiguration="Web_Services.Web_ServicesBehavior"
            name="Web_Services.Web_Services">
            <endpoint address="john" binding="wsDualHttpBinding" bindingConfiguration="WebServiceBinding"
              contract="Web_Services.IWeb_Services">
              <identity>
                <dns value="john" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
              <identity>
                <dns value="john" />
              </identity>
            </endpoint>
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:8000/Web_Services/Web_Services/" />
              </baseAddresses>
              <timeouts closeTimeout="00:10:10" openTimeout="00:10:00" />
            </host>
          </service>
        </services>
        <bindings>
          <wsDualHttpBinding>
            <binding closeTimeout="00:03:00" openTimeout="00:03:00" sendTimeout="00:03:00" receiveTimeout="00:03:00"
                     maxBufferPoolSize="100000000" maxReceivedMessageSize="100000000" bypassProxyOnLocal="false"
                     messageEncoding="Mtom" name="WebServiceBinding" transactionFlow="false" useDefaultWebProxy="false">
              <reliableSession inactivityTimeout="00:05:00"/>
              <readerQuotas maxDepth="32" maxStringContentLength="100000000" maxArrayLength="100000000"
                  maxBytesPerRead="100000000" maxNameTableCharCount="100000000" />
              <security mode="Message">
                <message clientCredentialType="UserName"/>
              </security>                    
            </binding>
          </wsDualHttpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior name="Web_Services.Web_ServicesBehavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
              <serviceCredentials>
                <serviceCertificate findValue="WebServiceCA" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
                <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Web_Services.UsernameValidator"/>
              </serviceCredentials>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>
    







    app.config for WPF
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <appSettings>
        <add key="CertName" value="CN=WebServiceCA" />
      </appSettings>
      <system.serviceModel>
            <bindings>
                <wsDualHttpBinding>
                    <binding name="WSDualHttpBinding_IWeb_Services" closeTimeout="00:01:00"
                        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                        bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                        maxBufferPoolSize="100000000" maxReceivedMessageSize="100000000"
                        messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true">
                        <readerQuotas maxDepth="32" maxStringContentLength="100000000" maxArrayLength="100000000"
                            maxBytesPerRead="100000000" maxNameTableCharCount="100000000" />
                        <reliableSession ordered="true" inactivityTimeout="00:05:00" />
                        <security mode="Message">
                            <message clientCredentialType="UserName" negotiateServiceCredential="true"
                                algorithmSuite="Default" />
                        </security>
                    </binding>
                </wsDualHttpBinding>
            </bindings>
            <client>
                <endpoint address=http://john/WebHost/HTTP_Web_Services/Web_Services.svc/john
                    binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IWeb_Services"
                    contract="IWeb_Services" name="WSDualHttpBinding_IWeb_Services" behaviorConfiguration="myClientBehavior">
                    <identity>
                        <dns value="WebServiceCA" />
                    </identity>
                </endpoint>
            </client>
        <behaviors>
          <endpointBehaviors>
            <behavior name="myClientBehavior">
              <clientCredentials>
                <serviceCertificate>
                  <authentication certificateValidationMode="Custom" customCertificateValidatorType="WebServiceWPF_Web.MyX509Validator, WebServiceWPF_Web" />
                </serviceCertificate>
              </clientCredentials>
            </behavior>
          </endpointBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>

Answers

All Replies

  • Wednesday, November 04, 2009 1:59 AMJohny79 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Can anyone shed any light on my setup? Is my web.config and app.config are setup correctly? Are there other settings on IIS that I need to setup?

    Any help is appreciated.
  • Thursday, November 05, 2009 12:57 AMJohny79 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    So I finally figured out why some system works and some doesn't. It is because of the Firewall. Now the big question is? For any clients to use the WPF, they will need to have their firewall disabled or open a port for the callback. Is it feasible to manually open a port on the client side for the callback or would the user need to do that? What is the ideal scenario for wsDualHttpBinding for WPF browser application? Looks like I may need to throw away this wsDualHttpBinding.
  • Monday, November 09, 2009 4:21 AMBin-ze ZhaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

    Firewalls very often blocks inbound connections to clients; the client may not be reachable from the server, it may be using NAT translation behind a router and so cannot be contacted without port forwarding being set up on the router. Both of these issues are showstoppers in real network topologies. You can take some small steps to help – you can specify what port the client should listen on for example by using the clientBaseAddress property of the WSDualHttpBinding.

    See this sample project for detailed code:
    http://www.codeproject.com/KB/WCF/ASENS.aspx?display=Print

    Also see the discussion in this thread to have a better understanding of using Duplex binding with firewall issue:
    http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/01f86bed-e6fd-4cbc-8192-217e0542ad3a

    Thanks
    Binzes
    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.