如何让Json从asmx web服务返回?

时间:2016-05-20 14:16:12

标签: c# json web-services asmx

我搜索了之前有关此问题的问题,但我无法得到解决方案。我的问题是我要求Bing Maps'来自我的asmx web服务的REST服务,我想从我的方法返回Json。此外,我将我的Web服务发布到Azure,当我调用它时,它会像这样返回。 我该如何解决这个问题?



<string xmlns="http://tempuri.org/">
<?xml version="1.0" encoding="utf-8"?> <string xmlns="http://tempuri.org/">Json elements in here</string>
</string>
&#13;
&#13;
&#13;

此处还有我的asmx服务代码:

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]

    public string GetBingRoute(string sourcelat, string sourcelong, string deslat, string deslong, string type)
    {

        //type should be Walking or Driving

        string address = "http://dev.virtualearth.net/REST/V1/Routes/" + type + "/?o=json&wp.0=" + sourcelat + "," + sourcelong + "&wp.1=" + deslat + "," + deslong + "&timeWithTraffic&key=_MYKEY_";

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        Stream resStream = response.GetResponseStream();

        StreamReader sr = new StreamReader(resStream);
        return sr.ReadToEnd();

    }

0 个答案:

没有答案