Access services from a console application - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Access services from a console application

  • Access services from a console application
  • Hello,

    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 'localhost:7987/.../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.