简体   繁体   中英

URI formats are not supported in webclient c#

I call my service as you can see like this :

  public ReceptionView ReceptionViewByReceptionId(string receptionId)
    {
        ClientRequest.Headers["Content-type"] = "application/json";
        ClientRequest.Encoding = System.Text.Encoding.UTF8;
        string result = ClientRequest.DownloadString("http://localhost:1111" + " /ReceptionService.svc/ReceptionViewByReceptionId/" + receptionId);

        var javascriptserializer = new JavaScriptSerializer();
        return javascriptserializer.Deserialize<ReceptionView>(result);
    }

But i get this error in DownloadString :

{"URI formats are not supported."} 

my service works ok and when i call my service by browser like this :

http://localhost:1111/ReceptionService.svc/ReceptionViewByReceptionId/1

I get the expected result .but in my application i can't

My service interface

 [WebGet( UriTemplate = "/ReceptionViewByReceptionId/{receptionId}", RequestFormat = WebMessageFormat.Json,
    ResponseFormat = WebMessageFormat.Json)]

    ReceptionView ReceptionViewByReceptionId(string receptionId);

As a note my function worked before without any error ,but today suddenly returns this error.

My fiddler result in browser: 在此处输入图片说明

The problem was the space here " /Reception as you can see in the url

string result = ClientRequest.DownloadString("http://localhost:1111" + " /ReceptionService.svc/ReceptionViewByReceptionId/" + receptionId);

I removed that and every thing worked fine .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM