none
ADFS Token generation working in C# but NOT in VB.Net RRS feed

  • Question

  • Below is code in c# to get token from server. The code in C# is working fine and I am able to receive the token from server but when I write same syntax in VB.net then I get exception.

    The framework for the code is same "4.6.2". App config of both the code are same

    var sEndPointAddress = "url";
    WS2007HttpBinding binding = new WS2007HttpBinding();
    binding.Security.Message.EstablishSecurityContext = false;
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
    binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
    binding.Security.Mode = SecurityMode.TransportWithMessageCredential;
    WSTrustChannelFactory trustChannelFactory = new WSTrustChannelFactory(binding, new EndpointAddress("https://IPAddress/adfs/services/trust/13/usernamemixed"));
    trustChannelFactory.TrustVersion = TrustVersion.WSTrust13;
    trustChannelFactory.Credentials.UserName.UserName = "username";
    trustChannelFactory.Credentials.UserName.Password = "password";
    RequestSecurityToken requestToken = new RequestSecurityToken(RequestTypes.Issue);
    requestToken.AppliesTo = new EndpointReference(sEndPointAddress);
    WSTrustChannel tokenClient = (WSTrustChannel)trustChannelFactory.CreateChannel();
    var token = tokenClient.Issue(requestToken);

    I have converted the same code in VB.Net but I am receving exception error.

    The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.

    Below is code in VB.Net


    Dim sEndPointAddress As String = "url"
    Dim Binding As New WS2007HttpBinding()
    Binding.Security.Message.EstablishSecurityContext = False
    Binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None
    Binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName
    Binding.Security.Mode = SecurityMode.TransportWithMessageCredential
    Dim trustChannelFactory As New WSTrustChannelFactory(Binding, New EndpointAddress("https://IPADDRESS/adfs/services/trust/13/usernamemixed"))
    trustChannelFactory.TrustVersion = TrustVersion.WSTrust13
    trustChannelFactory.Credentials.UserName.UserName = "UserName"
    trustChannelFactory.Credentials.UserName.Password = "Password"
    Dim requestToken As New RequestSecurityToken(RequestTypes.Issue)
    requestToken.AppliesTo = New EndpointReference("URL")
    Dim token As SecurityToken = trustChannelFactory.CreateChannel().Issue(requestToken)

    Monday, October 15, 2018 5:50 AM

All replies

  • Hi,

    try to fix the vb.net code:

    Dim token As SecurityToken = trustChannelFactory.CreateChannel().Issue(requestToken)

    to

    Dim tokenClient As WSTrustChannel = CType(trustChannelFactory.CreateChannel(), WSTrustChannel)
     Dim token = tokenClient.Issue(requestToken)

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 16, 2018 5:21 AM
  • @Alex;

    I have tried with your suggestion also but still i am facing the same issue.

    Tuesday, October 16, 2018 7:04 AM
  • Hi,

    try my code

     Dim sEndPointAddress = "url"
        Dim binding As WS2007HttpBinding = New WS2007HttpBinding()
        binding.Security.Message.EstablishSecurityContext = False
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None
        binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName
        binding.Security.Mode = SecurityMode.TransportWithMessageCredential
        Dim trustChannelFactory As WSTrustChannelFactory = New WSTrustChannelFactory(binding, New EndpointAddress("https://IPAddress/adfs/services/trust/13/usernamemixed"))
        trustChannelFactory.TrustVersion = TrustVersion.WSTrust13
        trustChannelFactory.Credentials.UserName.UserName = "username"
        trustChannelFactory.Credentials.UserName.Password = "password"
        Dim requestToken As RequestSecurityToken = New RequestSecurityToken(RequestTypes.Issue)
        requestToken.AppliesTo = New EndpointReference(sEndPointAddress)
        Dim tokenClient As WSTrustChannel = CType(trustChannelFactory.CreateChannel(), WSTrustChannel)
        Dim token = tokenClient.Issue(requestToken)

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 17, 2018 7:38 AM
  • @Alex:

    Tried initializing the variables the way you did and tried your code but still it did not solve the issue

    Wednesday, October 17, 2018 11:31 AM
  • Hi,

    Very strange, I think it should be independent of the code.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 24, 2018 8:20 AM