WCF Web API

Discussion in 'Site Programming, Development and Design' started by HeMac, Oct 12, 2011.

  1. I try to add RESTful service to my website, I followed samples from site:
    http://wcf.codeplex.com/ (Web API Preview 5)
    and integrated the sample to my web application.
    the sample worked well at local, but after I upgrate to Winhost server and changed
    client.Get("http://localhost:9000/api/contacts");
    to
    client.Get("http://www.myDomain.net/api/contacts");
    the Web API did not work.

    Can anyone give me a help, Thanks.
     
    Last edited by a moderator: Oct 14, 2015
  2. is there an-URL where we can see the error?
     
  3. can you turn the custom error off so we can see the real error message?
     
  4. Hi Allegro,

    I am back from work.

    I have turn <customErrors mode="Off">

    Now the error displayed.

    The error is caused by following code which access Web API, it works on local

    protected void ButtonGetContact_Click(object sender, EventArgs e)
    {
    HttpClient client = new HttpClient();
    HttpResponseMessage resp = client.Get("http://www.HeZi.net/api/contacts");

    if (resp.IsSuccessStatusCode)
    {
    List<Contact> contacts = resp.Content.ReadAs<List<Contact>>();

    LabelContactID.Text = contacts[0].ContactId.ToString();
    LabelContactName.Text = contacts[0].Name;
    }
    }
     
  5. Try to change the permission level to FULL

    modifying your web.config file as follow

    <configuration> <system.web> <trust level="Full" /> </system.web> </configuration>
     
  6. Yes, it works now.
    So it is about security.
    Thank you very much.
     

Share This Page