Inject WCF proxy with credentials using StructureMap
Posted
by Steve Horn
on Stack Overflow
See other posts from Stack Overflow
or by Steve Horn
Published on 2009-07-15T20:10:31Z
Indexed on
2010/03/16
19:01 UTC
Read the original article
Hit count: 276
dependency-injection
|wcf
I have a service proxy generated by svcutil which generated an interface(IStudentContract) and a concrete type implementing (StudentContractClient).
I'd like to have instances of StudentContractClient injected into my classes via StructureMap.
My proxy also needs to have credentials supplied as seen in this passing unit test:
<Test()> _
Public Sub Then_the_web_service_call_should_not_throw_an_exception()
Dim studentServiceProxy As New StudentContractClient
Dim credential As New NetworkCredential
credential.Domain = ConfigurationManager.AppSettings("something")
credential.UserName = ConfigurationManager.AppSettings("something")
credential.Password = ConfigurationManager.AppSettings("something")
studentServiceProxy.ClientCredentials.Windows.ClientCredential = credential
Dim result = studentServiceProxy.GetCurrentTeachersByStudentSepid(26899)
result.Count.ShouldEqual(4)
End Sub
My question is what would the structuremap configuration look like to have instances of IStudentContract injected with the credentials supplied?
Thanks for any help!
© Stack Overflow or respective owner