Service Agent & NetworkCredential

Topics: CAB & Smart Client Software Factory
Aug 2, 2006 at 4:43 AM
originally posted by: shuaux63

I have to use a web service with credential, so i ve implement a smart web reference and a service agent but i did'nt see anywhere to give NetworkCredential to the agent, i miss somethings ?

Aug 2, 2006 at 5:03 AM
originally posted by: shuaux63

Sorry, iv found my mistake, i ve not see the "partial" on my service so i can add my properties !

Aug 31, 2006 at 12:01 PM
originally posted by: bil_simser

What partial class are you referring to? I'm banging my head against the desk right now because I have to call a credential web service and don't see where to set credentials for the smart reference. I'm sure it's a silly simple app.config thing but for the life of me I can't track it down.
Aug 31, 2006 at 12:36 PM
originally posted by: PJackson

There's a Credentials property on the web reference itself, but the agent and proxy won't have access to it because they reference the interface. Add this property to the interface and it'll be exposed for you to modify from the proxy.
Aug 31, 2006 at 12:47 PM
originally posted by: bil_simser

Okay, that approach makes sense. However what interface are you saying to expose this on? The only one I can modify is the ServiceAgent. The interfaces coming back from the smart web reference are generated (and I don't think I should be modifying them directly). Can you give an example?
Aug 31, 2006 at 12:58 PM
originally posted by: PJackson

The method we used was this:

1) Create a new interface (IAsmxService) that exposes Credentials (we also expose UseDefaultCredentials, PreAuthenticate (sic?) and Url);
2) We have the partial class for the web reference implement this interface as well;
3) In the ServiceProxy ancestor we set the credentials and preauthenticate, as well as updating the Url because we have multiple possible endpoints;

We modified the guidance package so that this interface is added to the partial class automatically.
Aug 31, 2006 at 1:02 PM
originally posted by: bil_simser

Ahh, thanks for the insight as to how you did it. I didn't want to go to the trouble of modifing the guidance package. I thought there would have been an easier way to do this (like a system.web setting in app.config for the web proxy project). Thanks!
Aug 31, 2006 at 2:41 PM
originally posted by: MichaelDaniel

private void AddServices()
MyService.Service service = new MyService.Service();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
MyService.ServiceProxy proxy = new MyService.ServiceProxy(service);