Click here to Skip to main content
12,074,449 members (62,711 online)

Web Development

 
Questionis the $_GET exists? Pin
Jassim Rahma30-Oct-13 2:13
memberJassim Rahma30-Oct-13 2:13 
AnswerRe: is the $_GET exists? Pin
Richard MacCutchan30-Oct-13 3:10
mvpRichard MacCutchan30-Oct-13 3:10 
AnswerRe: is the $_GET exists? Pin
Peter Leow4-Nov-13 2:35
professionalPeter Leow4-Nov-13 2:35 
AnswerRe: is the $_GET exists? Pin
Killzone DeathMan9-Jan-14 2:08
groupKillzone DeathMan9-Jan-14 2:08 
QuestionSVG in IE8 Pin
ThetaClear29-Oct-13 12:12
memberThetaClear29-Oct-13 12:12 
AnswerRe: SVG in IE8 Pin
RedDk29-Oct-13 13:06
memberRedDk29-Oct-13 13:06 
GeneralRe: SVG in IE8 Pin
ThetaClear29-Oct-13 22:47
memberThetaClear29-Oct-13 22:47 
AnswerRe: SVG in IE8 Pin
Paulo Augusto Künzel4-Nov-13 4:43
professionalPaulo Augusto Künzel4-Nov-13 4:43 
GeneralRe: SVG in IE8 Pin
ThetaClear5-Nov-13 11:08
memberThetaClear5-Nov-13 11:08 
GeneralRe: SVG in IE8 Pin
Paulo Augusto Künzel5-Nov-13 12:47
professionalPaulo Augusto Künzel5-Nov-13 12:47 
Question(HTML5 + Javascript + javascript Libs) or Razor Engine Pin
OmniSource28-Oct-13 23:48
memberOmniSource28-Oct-13 23:48 
Questionhow to password reminder Pin
Jassim Rahma28-Oct-13 12:00
memberJassim Rahma28-Oct-13 12:00 
AnswerRe: how to password reminder Pin
Richard Deeming28-Oct-13 13:33
professionalRichard Deeming28-Oct-13 13:33 
QuestionASP Net WebAPI Newby Question Pin
Kevin Marois28-Oct-13 7:14
memberKevin Marois28-Oct-13 7:14 
I am VERY new to using WepAPI, and I have a problem. This might be a bit long, but I'm not sure what to post...

I'm using RestSharp....

I created a controller called AppSecurityController. It wraps calls to my security API. In it is a Login method:

The problem is that in the Login method, the Credential parameter is always null.

[System.Web.Http.HttpGet]
public LoginResponse Login(FMG.Entities.CredentialEntity Credentials)
{
    Marois.Common.AppSecurity.Entities.CredentialEntity credentials = new Marois.Common.AppSecurity.Entities.CredentialEntity
    {
        UserName = Credentials.UserName,
        Password = Credentials.Password
    };
 
    LoginResponse response = appSecurityBL.Login(credentials);
           
    return response;
}

My solution has a project called Entities. In it is the Credential class:

[Serializable]
[DataContract]
public class CredentialEntity : _BaseEntity
{
    [DataMember]
    public string Password { get; set; }
 
    [DataMember]
    public string UserName { get; set; }
}

In my client project I have local models, which also has a CredentialModel:
namespace FMG.UI.WPF.Shared.Models
{
  public class CredentialModel : _BaseModel
  {
      public string Password { get; set; }
 
      public string UserName { get; set; }
  }
}

I call to the WebAPI through a proxy class:

public LoginResponseModel Login(CredentialModel credentials)
{
    WebAPIExecutor webAPIExecutor = new WebAPIExecutor("/AppSecurity/Login/", Method.GET);
 
    webAPIExecutor.AddParameter(credentials);
 
    LoginResponseModel results = webAPIExecutor.Execute<LoginResponseModel>();
 
    return results;
}

WebAPIExecutor is a class for handling the RestSharp stuff:

public class WebAPIExecutor
{
    #region Private Fields
    private RestClient client;
    private RestRequest request;
    #endregion

    #region CTOR
    public WebAPIExecutor(string url, Method method = Method.POST)
    {
        if (string.IsNullOrEmpty(url))
        {
            throw new ArgumentNullException("Url");
        }
 
        // Set up the URL to the server
        setupServerURL();
 
        client = new RestClient(ServerAddress);
 
        client.AddHandler("text/plain", new JsonDeserializer());
 
        request = new RestRequest(url, method)
        {
            RequestFormat = RestSharp.DataFormat.Json
        };
    }
    #endregion

    #region Public Methods
    public void AddParameter(object value, string name = "")
    {
        if (value == null)
        {
            throw new ArgumentNullException("value");
        }
 
        Type type = value.GetType();
        bool isPrimitive = type.IsPrimitive;
 
        if(!string.IsNullOrEmpty(name) || (isPrimitive || type == typeof(string) || type == typeof(decimal)))
        {
            if (string.IsNullOrEmpty(name) && request.Method == Method.GET)
            {
                throw new ArgumentNullException("Parameter 'Name' cannot be empty for Get requests");
            }
 
            request.AddParameter(name, value);
        }
        else
        {
            request.AddBody(value);
        }
    }
 
    public T Execute<T>() where T : new()
    {
        IRestResponse<T> result = client.Execute<T>(request);
 
        int resultValue = (int)result.StatusCode;
 
        if (resultValue >= 299)
        {
            string message = string.Format("An error occured calling the WebAPI. {0} The status code is '{1}'. {2} The error message is {3}", 
                                            Environment.NewLine, result.StatusCode, Environment.NewLine, result.Content );
            MessageBox.Show(message, "WebAPI Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
 
            throw new Exception(message);
        }
 
        return result.Data;
    }
 
    public void Execute()
    {
        IRestResponse result = null;
 
        try
        {
            result = client.Execute(request);
 
            //TODO: Handle this differently.
            int resultCode = (int)result.StatusCode;
 
            //if (result.StatusCode != HttpStatusCode.OK)
            if (resultCode > 299)
            {
                string message = "the error message";  //<== omitted for brevitry
                throw new Exception(message);
            }
        }
        catch (Exception e)
        {
            throw e;
        }
    }
    #endregion
}

The parameter is being added with AddParameter and appears to be correct. The controller method is marked as HttpGet.

When I call from the proxy, through the WebAPIExecutor, I reach the controller and the parameter is null.

I'm am really clueless as to why the parameter is null in the controller. Can someone see what I'm doing wrong?

Many thanks
If it's not broken, fix it until it is

Questionget $_GET["id"] in window.location in PHP Pin
Jassim Rahma28-Oct-13 0:49
memberJassim Rahma28-Oct-13 0:49 
SuggestionRe: get $_GET["id"] in window.location in PHP Pin
Richard MacCutchan28-Oct-13 3:09
mvpRichard MacCutchan28-Oct-13 3:09 
AnswerRe: get $_GET["id"] in window.location in PHP Pin
Killzone DeathMan9-Jan-14 2:11
groupKillzone DeathMan9-Jan-14 2:11 
Questionwhy getting Strict Standards: Only variables should be passed by reference? Pin
Jassim Rahma28-Oct-13 0:20
memberJassim Rahma28-Oct-13 0:20 
Questionexpire login's session Pin
Jassim Rahma27-Oct-13 1:06
memberJassim Rahma27-Oct-13 1:06 
QuestionRe: expire login's session Pin
Richard MacCutchan27-Oct-13 3:07
mvpRichard MacCutchan27-Oct-13 3:07 
SuggestionRe: expire login's session Pin
thatraja28-Oct-13 2:02
mvpthatraja28-Oct-13 2:02 
Questionprofile address url validation Pin
Jassim Rahma26-Oct-13 12:05
memberJassim Rahma26-Oct-13 12:05 
AnswerRe: profile address url validation Pin
ProgramFOX27-Oct-13 0:43
member ProgramFOX27-Oct-13 0:43 
GeneralRe: profile address url validation Pin
Jassim Rahma27-Oct-13 0:56
memberJassim Rahma27-Oct-13 0:56 
AnswerRe: profile address url validation Pin
ProgramFOX27-Oct-13 6:39
member ProgramFOX27-Oct-13 6:39 
AnswerRe: profile address url validation Pin
Bernhard Hiller28-Oct-13 0:24
professionalBernhard Hiller28-Oct-13 0:24 
QuestionNetwork for web hosting Pin
is516726-Oct-13 9:24
memberis516726-Oct-13 9:24 
Questionmake <select> NOT required if checkbox is checked Pin
Jassim Rahma26-Oct-13 3:10
memberJassim Rahma26-Oct-13 3:10 
QuestionYears in Descending Order Pin
Jassim Rahma26-Oct-13 1:53
memberJassim Rahma26-Oct-13 1:53 
AnswerRe: Years in Descending Order Pin
Richard MacCutchan26-Oct-13 22:42
mvpRichard MacCutchan26-Oct-13 22:42 
GeneralRe: Years in Descending Order Pin
Jassim Rahma26-Oct-13 23:54
memberJassim Rahma26-Oct-13 23:54 
Questionplaceholder even if focus Pin
Jassim Rahma26-Oct-13 1:49
memberJassim Rahma26-Oct-13 1:49 
QuestionI want to display the xml content differentiating the docs by fields names and values any help please.. Below is my xml file content.. Pin
Indudhara26-Oct-13 1:17
memberIndudhara26-Oct-13 1:17 
Questionenable / disable combobox using checkbox Pin
Jassim Rahma25-Oct-13 11:04
memberJassim Rahma25-Oct-13 11:04 
AnswerRe: enable / disable combobox using checkbox Pin
S.K.Tripathi25-Oct-13 23:42
memberS.K.Tripathi25-Oct-13 23:42 
Questionread bit value into checkbox in PHP Pin
Jassim Rahma25-Oct-13 3:48
memberJassim Rahma25-Oct-13 3:48 
QuestionDynamic Data Scaffolding with static values Pin
vkEmerson24-Oct-13 10:39
membervkEmerson24-Oct-13 10:39 
QuestionDynamic questionnaire Pin
vkEmerson24-Oct-13 9:00
membervkEmerson24-Oct-13 9:00 
Questioninc or php for include files? Pin
Jassim Rahma24-Oct-13 0:53
memberJassim Rahma24-Oct-13 0:53 
Questionread the text of <select> instead of value Pin
Jassim Rahma23-Oct-13 1:47
memberJassim Rahma23-Oct-13 1:47 
Questionadd http to input box Pin
Jassim Rahma23-Oct-13 1:43
memberJassim Rahma23-Oct-13 1:43 
QuestionHow To Save Google map as image Pin
Jak Anil22-Oct-13 21:26
memberJak Anil22-Oct-13 21:26 
QuestionMultiple Selection Dropdown : Ordered list + JAVASCRIPT Pin
Member 1035161122-Oct-13 0:39
memberMember 1035161122-Oct-13 0:39 
AnswerRe: Multiple Selection Dropdown : Ordered list + JAVASCRIPT Pin
Wombaticus22-Oct-13 3:43
memberWombaticus22-Oct-13 3:43 
QuestionInteractive coloring page in HTML5 Pin
azjudy21-Oct-13 7:26
memberazjudy21-Oct-13 7:26 
QuestionScaffolding with Self referential Table in MVC Pin
nooshin21-Oct-13 1:57
membernooshin21-Oct-13 1:57 
Questiondatepicker problem Pin
Jassim Rahma20-Oct-13 4:27
memberJassim Rahma20-Oct-13 4:27 
Questionbest way to use webservices? Pin
Jassim Rahma19-Oct-13 9:38
memberJassim Rahma19-Oct-13 9:38 
AnswerRe: best way to use webservices? Pin
Ali Al Omairi(Abu AlHassan)19-Oct-13 23:03
memberAli Al Omairi(Abu AlHassan)19-Oct-13 23:03 
GeneralRe: best way to use webservices? Pin
Jassim Rahma20-Oct-13 3:57
memberJassim Rahma20-Oct-13 3:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.160208.1 | Last Updated 11 Feb 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid