Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Implementing Webinvoke with GET and POST in WCF

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 518
    Comment on it

    When working with WCF Windows Communication Foundation you need to know what kind of operation you are going to perform for doing that you will create a operation that could be of type GET or POST.

     

    While using the WebInvoke  you need to understand that you don't have any sensitive value which will pass as a parameter or any sensitive data returning from your function.

     

            [OperationContract]
            [WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "GetLocation/{accessToken}")]
            LocationListResponse GetLocation(string accessToken); 

    In this i have made an operation which is of get type and i am passing access token as parameter which is wrong because access token is a sensitive information that is used for finding credentials of any user.

     

    So what we will do is we will use this operation in POST form

     [OperationContract]
            [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "GetLocation")]
            LocationListResponse GetLocation(string accessToken);

    This is the write way of creating it in WCF because while using POST, browser caches and cookies are disabled so no sensitive information gets stored into the Browser or in the URL

     

    Best way to implement Webinvoke with GET in WCF while you don't have any sensitive information associated with the operation

     [OperationContract]
            [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "GetCompany")]
            CompanyResponse GetCompany();
    

    Here i have implemented it because i don't have any sensitive information associated with this operation.

    My return type here is JSON it could be XML also

    URI Template is the name of API through which it is called by the user

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: