wso2 data services返回json数据方法

一、首先要修改下配置文件。

修改\repository\conf\axis2目录下axis2.xml与axis2_client.xml配置文件。

增加<parameter name="httpContentNegotiation">true</parameter>配置

axis2.xml代码段如下:

    <!-- ================================================= -->

    <!-- Parameters -->

    <!-- ================================================= -->

    <parameter name="hotdeployment">true</parameter>

    <parameter name="hotupdate">true</parameter>

    <parameter name="enableMTOM" locked="false">optional</parameter>

    <parameter name="cacheAttachments">true</parameter>

    <parameter name="attachmentDIR">work/mtom</parameter>

    <parameter name="sizeThreshold">4000</parameter>

    <parameter name="httpContentNegotiation">true</parameter>

    <parameter name="EnableChildFirstClassLoading">${childfirstCL}</parameter>

axis2_client.xml代码段如下:

    <!--If turned on with use the Accept header of the request to determine the contentType of the

    response-->

    <parameter name="httpContentNegotiation">true</parameter>


二、访问服务

            WebClient w = new WebClient();

            w.Headers.Add(HttpRequestHeader.Accept, "application/json");           

            using (StreamReader sr = new StreamReader(w.OpenRead("http://192.168.1.123:9763/services/ccjy.HTTPEndpoint/getrestnews?num=4")))

            {                

                string a =sr.ReadToEnd();                

            }

 

你可能感兴趣的:(service)