More in this section
Forums / Developing with Sitefinity / Access services from a console application

Access services from a console application

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
1 posts, 0 answered
  1. David
    David avatar
    0 posts
    18 Sep 2016
    11 Dec 2016
    Link to this post


    I build a console application to make a synchronization between several xml files provided by an external source and some custom content types inside Sitefinity. This application call several services builded with Servicestack and hosted by the Sitefinity application.

    To access these services, the console application log a user with this piece of code:

    public static NameValueCollection SignIn(string siteUrl, string username, string password)
        var formData = String.Format(SignInQueryStringFormat, username, password);
        var bytes = Encoding.UTF8.GetBytes(formData);
        WebRequest signInRequest = WebRequest.Create(AuthenticationHelper.GetSignInUrl(siteUrl));
        signInRequest.Method = "POST";
        signInRequest.ContentType = FormDataContentType;
        signInRequest.ContentLength = bytes.Length;
        Stream dataStream = signInRequest.GetRequestStream();
        dataStream.Write(bytes, 0, bytes.Length);
        Stream objStream = signInRequest.GetResponse().GetResponseStream();
        StreamReader objReader = new StreamReader(objStream);
        var token = objReader.ReadToEnd();
        var nameValueColl = HttpUtility.ParseQueryString(token);
        var bootstrapToken = nameValueColl[AuthenticationHelper.SwtWrapParam];
        var requestHeaders = new NameValueCollection();
        string tokenContent = string.Format(AuthenticationHelper.AuthorizationHeaderFormat, bootstrapToken);
        requestHeaders.Add(AuthenticationHelper.AuthorizationHeaderParameterName, tokenContent);
        return requestHeaders;


    The request header generate by the signin method is put in the header of the request to call the Services.

    After that I receive a 401 error Unauthorized
    With the message : Missing configuration of security for the issuer tokens 'http://localhost:7987/SiteFinityWebApp/Sitefinity/Authenticate/SWT'

    So I tried to put a SecurityTokenIssuers in the backend with the following url:

    After that another error was thrown : 401: Unauthorized | TokenExpired

    I don't know what I'm doing it wrong?

    Could someone help me?

    Thanks in advance.


1 posts, 0 answered