xmlns=''> was not expected. - There is an error in XML document (2, 2)

前端 未结 3 1103
北恋
北恋 2021-01-03 19:41

Im trying to deserialize the response from this simple web service

Im using the following code:

WebRequest request = WebRequest.Create(\"http://inb37         


        
3条回答
  •  误落风尘
    2021-01-03 19:58

    You want to deserialize the XML and treat it as a fragment.

    There's a very straightforward workaround available here. I've modified it for your scenario:

    var webRequest = WebRequest.Create("http://inb374.jelastic.tsukaeru.net:8080/VodafoneDB/webresources/vodafone/04111111");
    
    using (var webResponse = webRequest.GetResponse())
    using (var responseStream = webResponse.GetResponseStream())
    {
        var rootAttribute = new XmlRootAttribute();
        rootAttribute.ElementName = "response";
        rootAttribute.IsNullable = true;
    
        var xmlSerializer = new XmlSerializer(typeof (string), rootAttribute);
        var response = (string) xmlSerializer.Deserialize(responseStream);
    }
    

提交回复
热议问题