Saturday, 14 September 2013

WP8 WebClient Not Found Error

WP8 WebClient Not Found Error

I am trying to POST JSON data to my WCF service but I get a Not Found error.
Code:
public void ReportSighting()
{
Sighting.Instance.TypeId = "SightingTypes/2";
Sighting.Instance.BrandId = "brands/1";
string jsonData = JsonConvert.SerializeObject(Sighting.Instance);
WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] =
"application/json";
var uri = new Uri("myUrl", UriKind.Absolute);
webClient.Headers[HttpRequestHeader.ContentLength] =
jsonData.Length.ToString();
webClient.AllowWriteStreamBuffering = true;
webClient.Encoding = System.Text.Encoding.UTF8;
webClient.UploadStringAsync(uri, "POST", jsonData.ToString());
webClient.UploadStringCompleted += new
UploadStringCompletedEventHandler(postComplete);
System.Threading.Thread.Sleep(200);
}
private void postComplete(object sender,
UploadStringCompletedEventArgs e)
{
//Response result =
JsonConvert.DeserializeObject<Response>(e.Result);
try
{
MessageBox.Show(e.Result);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Error: InnerException = {System.Net.WebException: The remote server
returned an error: NotFound. ---> System.Net.WebException: The remote
server returned an error: NotFound. at
System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult
asyncResult) at Syst...

No comments:

Post a Comment