You must Sign In to post a response.
  • Category: WCF

    REST method with both XML and JSON responce

    I want to create rest method that can support request/responce in both xml and json formats.

    I am trying in bellow way, but its not working getting error.
    any idea on this?

    Code in IService.cs :

    [WebGet(UriTemplate = "/Login/{UserID}/{Password}")]
    Responce Login(string UserID, string Password);

    Code in Service.cs :

    public Responce Login(string UserID, string Password)
    objResponce = new Responce();
    objResponce.MessageType = Responce.ResponceType.Warning.ToString();
    string Con = GetConnectionString(UserID, Password); //Method to check valid user or not
    if (Con.Trim().Length != 0)
    objResponce.Message = "you have logged in Successfully";
    objResponce.Message = "Please Enter Valid UserID,Password";

    catch (Exception ex)
    through ex;
    return objResponce;

    My Config settings :
    <service name="OnePointAPI.OnePointAPIService">
    <endpoint address="JSON" binding="webHttpBinding" contract="OnePointAPI.IOnePointAPIService" behaviorConfiguration="webJSON" ></endpoint>
    <endpoint address="XML" binding="basicHttpBinding" contract="OnePointAPI.IOnePointAPIService" behaviorConfiguration="webXML" ></endpoint>
    <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
    <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
    <serviceDebug includeExceptionDetailInFaults="false"/>
    <behavior name="webJSON">
    <webHttp defaultOutgoingResponseFormat="Json"/>
    <behavior name="webXML">
    <webHttp defaultOutgoingResponseFormat="Xml" />
  • #755562

    pls can you tell the exact return error given by WCF rest. then we try to give solution.

    Kalandiyur Subramanian Mohan

  • #755589
    What exactly is the error. You can pass both the return type as the result will determine the type of data returned.

    Please mentioned this issue and the line of code where you are getting this error.

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #755601
    initially i got error as,
    The endpoint at 'http://pspl-pc103/1PointAPI/OnePointAPIService.svc/XML' does not have a Binding with the None MessageVersion. 'System.ServiceModel.Description.WebHttpBehavior' is only intended for use with WebHttpBinding or similar bindings.
    To resolve this i have removed behaviorConfiguration form bellow tag,
    <endpoint address="XML" binding="basicHttpBinding" contract="OnePointAPI.IOnePointAPIService" behaviorConfiguration="webXML"></endpoint>
    Now The end points in my applications are as follows,
    <endpoint address="JSON" binding="webHttpBinding" contract="OnePointAPI.IOnePointAPIService" behaviorConfiguration="web" ></endpoint>
    <endpoint address="XML" binding="basicHttpBinding" contract="OnePointAPI.IOnePointAPIService" ></endpoint>

    Now request(webHttpBinding) with JSON address working fine and getting result pefectly,
    where as when i request(basicHttpBinding) like bellow , i am not getting any response(empty screen)

  • #755627
    When you use RestFul Wcf Service. Then you provide WebHttpBinding for hosting service.. also you have to explicitly mention Responceformat as Json/Xml then it return data

    Umesh Bhosale

  • Sign In to post your comments