tags:

views:

122

answers:

0

Greetings I have to following error while connecting to my WCF Service using custom binding

An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail

web.config looks as follows:

<system.serviceModel>
<bindings>
  <customBinding>
    <binding name="BindingEndpoint"
             closeTimeout="00:01:00"
      openTimeout="00:01:00"
      receiveTimeout="00:10:00"
      sendTimeout="00:01:00">
      <!--<reliableSession ordered="true" inactivityTimeout="00:05:00"  />-->
      <security authenticationMode="MutualCertificate" requireSecurityContextCancellation="true">

        <localServiceSettings maxClockSkew="03:00:00" timestampValidityDuration="00:25:00" />
        <localClientSettings maxClockSkew="03:00:00" timestampValidityDuration="00:25:00" />
        <secureConversationBootstrap>
          <localServiceSettings maxClockSkew="03:00:00" timestampValidityDuration="00:25:00" />
          <localClientSettings maxClockSkew="03:00:00" timestampValidityDuration="00:25:00" />
        </secureConversationBootstrap>
      </security>
      <textMessageEncoding messageVersion="Soap12WSAddressing10" writeEncoding="utf-8"/>
      <sslStreamSecurity requireClientCertificate="false"/>
      <httpsTransport/>
    </binding>
  </customBinding>
  <!--</wsHttpBinding>-->
</bindings>

 <identity>
  <dns value="WCFServer"/>
 </identity>
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>

      <serviceThrottling maxConcurrentCalls="2147483647"
        maxConcurrentSessions="2147483647"
        maxConcurrentInstances="2147483647" />

      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
 <serviceMetadata httpsGetEnabled="true"/>

 <serviceDebug includeExceptionDetailInFaults="true"/>
      <serviceCredentials>
        <clientCertificate>
          <authentication certificateValidationMode="PeerTrust"/>
        </clientCertificate>
        <serviceCertificate findValue="WCFServer"
                            storeLocation="LocalMachine"
                            storeName="My"
                            x509FindType="FindBySubjectName"/>
      </serviceCredentials>
</behavior>

And then on my client application I create a proxy as follows:

CustomBinding myBinding = new CustomBinding();
        TransactionFlowBindingElement transactionFlow = new TransactionFlowBindingElement();
        myBinding.Elements.Add(transactionFlow);

        TransportSecurityBindingElement securityBinding = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
        securityBinding.LocalClientSettings.MaxClockSkew = new TimeSpan(3, 0, 0);
        securityBinding.LocalServiceSettings.MaxClockSkew = new TimeSpan(3, 0, 0);
        myBinding.Elements.Add(securityBinding);

        HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement();
        httpsTransport.MaxReceivedMessageSize = 2147483647;
        myBinding.Elements.Add(httpsTransport);

        myBinding.CloseTimeout = new TimeSpan(0, 1, 0);
        myBinding.ReceiveTimeout = TimeSpan.MaxValue;
        EndpointAddress myEndpoint =
        new EndpointAddress(new Uri("https://localhost/Service/Service.svc"), EndpointIdentity.CreateDnsIdentity("WCFServer"));

        ContractDescription contract = ContractDescription.GetContract(typeof(IWCFSeekService));

        ServiceEndpoint serviceEndPoint = new ServiceEndpoint(contract);
        serviceEndPoint.Binding = myBinding;
        serviceEndPoint.Address = myEndpoint;

        ClientCredentials item = new ClientCredentials();

        item.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust;
        item.ServiceCertificate.Authentication.TrustedStoreLocation = StoreLocation.LocalMachine;
        item.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, "WCFClient");
        serviceEndPoint.Behaviors.Add(item);

        ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior()
        {
            MaxConcurrentCalls = 500,
            MaxConcurrentSessions = 500,
            MaxConcurrentInstances = 500
        };


        ChannelFactory<IWCFSeekService> myChannelFactory =
        new ChannelFactory<IWCFSeekService>(serviceEndPoint);

        myChannelFactory.Credentials.Windows.ClientCredential.UserName = "root";
        myChannelFactory.Credentials.Windows.ClientCredential.Password = "xxxxxx";
        myChannelFactory.Credentials.UserName.UserName = "user";

        return myChannelFactory;

Please help me with this issue as I am trying to resolve this for 2 days without success I would like to add that previously when I had wsHttpBinding it worked fine with certificates