WCF client certification

General Tech QA/Testing 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on QA/Testing related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I have a WCF service which uses basicHttpBinding. Now I want to secure my methods">methods so that no one can create a proxy and use my method. I used WCF client certification from msdn. But cant move further. here is my web.config

 

   address="http://localhost:57246/Service1.svc" binding="basicHttpBinding"
    bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
    name="BasicHttpBinding_IService1" />


   name="Microsoft.ServiceModel.Samples.CalculatorService"
           behaviorConfiguration="DataServiceBehavior">
    
      
         baseAddress="http://localhost:57246/Service1.svc"/>
      
    
     address=""
       binding="basicHttpBinding"
       bindingConfiguration="Binding1"
       contract="ServiceReference1.IService1" />

     address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" />
  



  
     name="BasicHttpBinding_IService1">
       mode="Message">
         realm="" />
         clientCredentialType="Certificate" />
      
    
  




  
     name="DataServiceBehavior">
       httpGetEnabled="True"/>
       includeExceptionDetailInFaults="False" />

      
         findValue="localhost" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
        

           certificateValidationMode="PeerOrChainTrust" />
        
      
    
  

now what should pass call form the c sharp. I have a method in WCF named showGrid.

public DataSet showGrid()
    {
        SqlDataAdapter da = new SqlDataAdapter("Select * FROM Resources", con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        return ds;
    }

and trying to call it like this on a button click

protected void btnShow_Click(object sender, EventArgs e)
    {
        var client = new ServiceReference1.Service1Client();


 client.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySubjectName, "localhost");
        client.showGrid();
        GridView1.DataSource = client.showGrid();
        
                                                
                                                
0 views
0 shares
profilepic.png
manpreet 2 years ago

Just add client certificate like this

client.ClientCredentials.ClientCertificate.Certificate = yourcert;

Edit:

        X509Certificate2 yourcert= null; 
        var store = new X509Store(storeName, storeLocation);

        store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
        var certCollection = store.Certificates.Find(findType, thumbprint, false);
        if (certCollection.Count>0)
            yourcert= certCollection[0];
        store.Close();

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.