0

我正在尝试将 JSON 数据发布到我的 WCF 服务,但出现 Not Found 错误。

代码:

    public void ReportSighting()
    {
        var uri = new Uri("http://demo.notifysolutions.com/MobileService.svc/ReportSighting", UriKind.Absolute);

        var webClient = new WebClient();
        webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
        webClient.Encoding = Encoding.UTF8;
        webClient.Headers[HttpRequestHeader.ContentLength] = jsonData.Length.ToString();
        webClient.AllowWriteStreamBuffering = true;
        webClient.UploadStringAsync(uri, "POST", jsonData);
        webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(ReportSightingCompleted);
        System.Threading.Thread.Sleep(200);
    }

    private void PostCompleted(object sender, UploadStringCompletedEventArgs e)
    {
        try
        {
            MessageBox.Show(e.Result);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    } 

错误:InnerException = {System.Net.WebException:远程服务器返回错误:NotFound。---> System.Net.WebException:远程服务器返回错误:NotFound。在 System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) 在 Syst...

我已经在 Fiddler 中尝试过,效果很好。

4

0 回答 0