1

I am trying to connect to servicebus and getting data from it, it seems since I've got the token I must reuse it evertime I make a request what's wrong with this code?here is the error I've got at the last line The remote server returned an error: (401) Unauthorized.

//sample usage string mydata1 = string.Format(Constants.myData, brfId);

public static readonly myData= "https://sdgsdg.servicebus.windows.net/sgsdg/gdgsg/{0}";



//sample usage - string agendaByBriefingDetailIdURI = string.Format(Constants.myData2 BriefingID, accessCode);

public static readonly string myData2= "https://sdgsg.servicebus.windows.net/sdg/dgsg/{0}/{1}";

    string SCOPE = "http://lalalalala.servicebus.windows.net/";

    string WRAP_PASSWORD = "lalalalalala"

    string WRAP_USERNAME = "lalalala";

    string ACS_NAMESPACE = "lalalalala";

    WebClient client = new WebClient();

    client.BaseAddress = string.Format("https://{0}.accesscontrol.windows.net", ACS_NAMESPACE);




    NameValueCollection values = new NameValueCollection();

    values.Add("wrap_name", WRAP_USERNAME);

    values.Add("wrap_password", WRAP_PASSWORD);

    values.Add("wrap_scope", SCOPE);


    // WebClient takes care of the URL Encoding

    byte[] responseBytes = client.UploadValues("WRAPv0.9", "POST", values);


    // the raw response from ACS

    string response = Encoding.UTF8.GetString(responseBytes);

    string token = response.Split('&').Single(x => x.StartsWith("wrap_access_token=", StringComparison.OrdinalIgnoreCase)).Split('=')[1];

    string decodedToken = HttpUtility.UrlDecode(token);

    string.Format("WRAP access_token=\"{0}\"", HttpUtility.UrlDecode(token));


    WebClient webClient = new WebClient();

    webClient.Headers["Authorization"] = string.Format("WRAP access_token=\"{0}\"", HttpUtility.UrlDecode(token));


    string returnString = webClient.DownloadString(string.Format(mystaticre, 10));
Emily Gerner
  • 2,427
  • 16
  • 16
Sharp
  • 121
  • 1
  • 2
  • 16
  • Hi elmily,what do you think is better between this way above and thishttp://stackoverflow.com/questions/35272537/how-do-i-get-data-from-azure-queue-message-service-bus? – Sharp Feb 09 '16 at 20:47

0 Answers0