Link to home
Start Free TrialLog in
Avatar of Buz007
Buz007Flag for Canada

asked on

.NET WebService client with certificates

Hello all.

I am trying to write a simple web service client using Visual Studio 2010.
The WSDL for the service is here:
http://webservices.telus.com/parlayx_wappush_send_service_1_0.wsdl

I was able to call the service using SoapUI using the given certificate file (ext. .crt) and password.

I created a simple console application and added the Web Reference to the service and got a proxy object to call the service.

I spent many hours trying to write a simple function to call the service from my .NET console application but it fails with error:
' Impossible to create a secure SSL/TSL canal'

    static void Main(string[] args)
    {
      SendWapPushService swps = new SendWapPushService();
      sendWapPush swp = new sendWapPush();
      X509Certificate cert = X509Certificate.CreateFromCertFile("MyCertFile.crt");
      swps.ClientCertificates.Add(cert);
      NetworkCredential nwCredential = new NetworkCredential("<user>", "<pwd>");
      swps.Credentials = nwCredential;

      swp.address = ... (same params as with SoapUI test)
      ...
      try
      {
        swps.sendWapPush(swp);
      }
      catch (Exception ex)
      {
         ...
      }

I just can't find how to setup the call (credentials / certificate) ... in my .Net example.

Ant help would be greatly appreciated.

Best regards

Noel
No matter what i try, it alway return that same exception ...
Avatar of lojk
lojk
Flag of United Kingdom of Great Britain and Northern Ireland image

The service, when accessed from a browser over https reports that the certifcate is not valid or self-signed (i.e. not trusted by your browser and/or machine certificate store).

here is the error from the Add Service Reference box in VS2010 on my machine...

There was an error downloading 'https://webservices.telus.com/parlayx_wappush_send_service_1_0.wsdl'.
The request was aborted: Could not create SSL/TLS secure channel.
Metadata contains a reference that cannot be resolved: 'https://webservices.telus.com/parlayx_wappush_send_service_1_0.wsdl'.
Could not establish secure channel for SSL/TLS with authority 'webservices.telus.com'.
The request was aborted: Could not create SSL/TLS secure channel.
If the service is defined in the current solution, try building the solution and adding the service reference again.

So until you get the site certificate signed by a CA (i.e. create the cert on the machine issuing the ssl channel and generate a CSR and install the signed reply on the IIS box) i dont think it will work.

As far as i am aware you cant just copy the cert from another machine unless there is a valid certificate trust chain for that certificate on that box - I dont think primarily it is an authentication issue but what are you running this on? IIS6/7?
Not sure if you've already seen this one but here is a fairly thorough walkthrough that may help (that is more specific to your question than my answer is)..

http://www.codeproject.com/Articles/18601/An-easy-way-to-use-certificates-for-WCF-security
hmm, where do you see 'service' class??? I get only 'client' :)
When adding the service to my (test) console app here is what i get...

(see attached)
Capture9.PNG
works fine when i add it without SSL

(see attached)
Capture10.PNG
exactly, so my question still stands :) -

where does "SendWapPushService swps = new SendWapPushService();" in OP come from?
huh? I dont understand what you mean?

The name SendWapPushService is effectively the name/location of the class where your WCF service is declared - when adding the service reference, other than the namespace you provide the rest is dervied from the info in the wsdl and/or the url...
unless I'm missing something obvious, the only thing one [usually] provides when adding a reference is the reference name (ie namespace) which is then added as '<your main manespace>.<your ref name>', and then the classes names inside the proxy are taken from wsdl file.
Yep - what i am saying is that your declaring WCF class/service name (must) contains the word 'Service' and that is also hosted in a similiarly named Virtual Directory/Application but i dont understand what you are actually asking me in ID: 37786641or ID: 37786894

Can you clarify what your actual question is please - did my original comment not help?
I'm not the one who asked the question :), I've been trying to help.

so what I meant in my posts is very simple:

the author of the OP asked "I am trying to write a simple web service client using Visual Studio 2010.", so once you added the service reference (yes, it shows you service name - SendWapPushService with one interface, but it obviously can have  many) you then add something like

using mytest.ServiceReference1;

Open in new window

...

to your console app. Then you want to create an instance of the client, don't you? In order do do it and to see all offered classes, you could write something like

mytest.ServiceReference1. <---- 'dot' here, to see everything

Open in new window


so once you did it with provided wsdl, the only potential 'main' client class I see is SendWapPush1Client.

Hence my question - NOT the one that author asked... :) That's it. Am I missing something here?
ASKER CERTIFIED SOLUTION
Avatar of Buz007
Buz007
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
weird, but it doesn't appear for me :)
tried with vs2010, vs2008 - I see only xxxClient class, but anyway, glad to hear you found the solution.
was gonna object to the close as ID: 37786271 does come pretty close to your solution but cant be bothered

apologies to alexy_gusev - got a bit confused there...
Avatar of Buz007

ASKER

Because it works and solves my problem.