Question Timeout accessing my self hosted WCF SSL service.

groadsvb

Well-known member
Joined
Nov 13, 2006
Messages
75
Programming Experience
Beginner
I hope that I get all the steps correct to explain what I did. In summary I created my on certificates to develop and test a self hosted WCF using SSL.
1) i create the CA
2) I moved that CA to the Certificates Trusted Root Authority
3) I created a self signed certificate from the CA i created
4) I wrote my WCF and Self hosted it.
5) I wrote a console app and added a service reference to service in step 4 and ran the app and it worked! Cool.

6) I wrote and new console app but did not add a service reference. I wrote my own code to call the self hosted WCF but I get a timeout. Below is the code that times out. The error is {"The operation has timed out"}.
my x509 certificate path is to the self signed file that I exported from mmc.

VB.NET:
Imports System.Net
Imports System.IO
Imports System.Security.Cryptography.X509Certificates
Module Module1

    Sub Main()

        Dim webRequest As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://localhost:10991/WCFCalculator")
        webRequest.Method = "POST"
        webRequest.ContentType = "text/xml; charset=utf-8"
        Dim content = "<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/""><s:Body><add xmlns=""http://Microsoft.ServiceModel.Samples""><a1>1</a1><a2>1</a2></add></s:Body></s:Envelope>"
        webRequest.ContentLength = content.Length
        webRequest.ClientCertificates.Add(New X509Certificate2("C:\TestData\ssl\exportedGary1.pfx", "Kangaroo", X509KeyStorageFlags.MachineKeySet))
        webRequest.Timeout = 10000
        webRequest.Headers.Add("SOAPAction", "http://Microsoft.ServiceModel.Samples/IWCFCalculator/add")


        Using sw As New StreamWriter(webRequest.GetRequestStream())
            sw.Write(content)
        End Using


        Using sr As New System.IO.StreamReader(webRequest.GetResponse().GetResponseStream)
            Dim data = sr.ReadToEnd
            Console.WriteLine(data)
            Console.Read()
        End Using
    End Sub

End Module

All help with this is greatly appreciated.
 
The ssl service url must be https at least, not http. Why would you not use the client proxy?
 
I did see that I copy over the code when I had it as non ssl. I have https in the running version that gave me the time out. I just got it to run with out the timeout but I am not sure why this makes a difference yet. If anyone has input, welcome all. To get it to work I changed the storage flags from MachineKeySet to UserKeySet and I no longer time out.
 
Hi JohnH:
Thanks for the reply. I do not completely understand all about the request and hosting so I may not understand completely the client proxy concept. To finish the task that I have been assigned I don't know if I have that option. Or is a client proxy always an option when writing this type of exchange?
 
Back
Top