简体   繁体   English

WebClient C#不支持URI格式

[英]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 : 但是我在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 问题是这里的空格" /Reception ,您可以在url中看到

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

I removed that and every thing worked fine . 我删除了所有内容,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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