Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net Json在生产环境中不响应Json_.net_Jquery_Ajax_Web Services_Production Environment - Fatal编程技术网

.net Json在生产环境中不响应Json

.net Json在生产环境中不响应Json,.net,jquery,ajax,web-services,production-environment,.net,Jquery,Ajax,Web Services,Production Environment,在本地主机上,我的IIS 7.5在windows 7上运行。在我的生产环境中,我在服务器Ent上运行iis 7。2008年 当我将代码发布到生产环境并运行jQueryAjax调用时,我会得到一个XML响应,并且我希望得到一个JSON响应 我使用fiddler比较了两个请求头,它们是相同的 编辑:我的服务具有[ScriptService]: [ScriptService] public class Satellites : System.Web.Services.WebService { web

在本地主机上,我的IIS 7.5在windows 7上运行。在我的生产环境中,我在服务器Ent上运行iis 7。2008年

当我将代码发布到生产环境并运行jQueryAjax调用时,我会得到一个XML响应,并且我希望得到一个JSON响应

我使用fiddler比较了两个请求头,它们是相同的

编辑:我的服务具有[ScriptService]:

[ScriptService]
public class Satellites : System.Web.Services.WebService {
webmethod:

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
public List<Satellite> GetSatellites()
{
    List<Satellite> satellites;

    if (!CacheHelper.Get(strSatelliteKey, out satellites))
    {
        //satellites not found so retrieve and add to cache for next lookup.
        satellites = GetLatestSatellites();
        CacheHelper.Add(satellites, strSatelliteKey);

    }

    return satellites;
}
生产部门的答复:

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfSatellite xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://cstars.miami.edu/SAR">
  <Satellite>
    <id>10967</id>
    <name>SEASAT1</name>
  </Satellite>
  <Satellite>
    <id>16613</id>
    <name>SPOT1</name>
  </Satellite>
  <Satellite>
    <id>20436</id>
    <name>SPOT2</name>
    <tle0>SPOT 2</tle0>
    <tle1>1 20436U 90005A   10320.17586019  .00000436  00000-0  83185-4 0  7240</tle1>
    <tle2>2 20436  98.6342  56.4544 0155718 145.6368 215.5023 14.62070104 81087</tle2>
  </Satellite>
  <Satellite>
    <id>21574</id>
    <name>ERS1</name>
  </Satellite>
  <Satellite>
    <id>21867</id>
    <name>JERS1</name>
  </Satellite>
  <Satellite>
    <id>23560</id>
    <name>ERS2</name>
    <tle0>ERS-2</tle0>
    <tle1>1 23560U 95021A   10320.16163206  .00000093  00000-0  50826-4 0  7517</tle1>
    <tle2>2 23560  98.5539  32.9598 0001338  91.0148 269.1209 14.32246397814217</tle2>
  </Satellite>
  <Satellite>
    <id>23710</id>
    <name>RSAT1</name>
    <tle0>RADARSAT-1</tle0>
    <tle1>1 23710U 95059A   10320.17983791  .00000119  00000-0  63183-4 0  8807</tle1>
    <tle2>2 23710  98.5810 324.6746 0001101  92.8062  40.0723 14.29987468784696</tle2>
  </Satellite>
  <Satellite>
    <id>25260</id>
    <name>SPOT4</name>
    <tle0>SPOT 4</tle0>
    <tle1>1 25260U 98017A   10320.17010216  .00000053  00000-0  45000-4 0  7757</tle1>
    <tle2>2 25260  98.6410  27.5855 0001153 118.8023 241.3191 14.20071681655704</tle2>
  </Satellite>
  <Satellite>
    <id>25682</id>
    <name>LSAT7</name>
    <tle0>LANDSAT 7</tle0>
    <tle1>1 25682U 99020A   10320.17475749  .00000092  00000-0  30424-4 0  4435</tle1>
    <tle2>2 25682  98.2322  26.4024 0001343 107.7462 252.3889 14.57097903616361</tle2>
  </Satellite>
  <Satellite>
    <id>25994</id>
    <name>TERRA1</name>
    <tle0>TERRA</tle0>
    <tle1>1 25994U 99068A   10320.19170658  .00000163  00000-0  46333-4 0  3452</tle1>
    <tle2>2 25994  98.2175  32.5202 0000685  91.9171 268.2128 14.57106702580447</tle2>
  </Satellite>
  <Satellite>
    <id>27386</id>
    <name>ENVISAT1</name>
    <tle0>ENVISAT</tle0>
    <tle1>1 27386U 02009A   10320.19615002  .00000074  00000-0  39337-4 0  6231</tle1>
    <tle2>2 27386  98.5352  25.2483 0001101 100.3084 259.8244 14.37466989455514</tle2>
  </Satellite>
  <Satellite>
    <id>27421</id>
    <name>SPOT5</name>
    <tle0>SPOT 5</tle0>
    <tle1>1 27421U 02021A   10320.21390906  .00000169  00000-0  10000-3 0  6893</tle1>
    <tle2>2 27421  98.7199  32.2015 0000869  81.7846 312.1186 14.20026544442540</tle2>
  </Satellite>
  <Satellite>
    <id>27424</id>
    <name>AQUA</name>
    <tle0>AQUA</tle0>
    <tle1>1 27424U 02022A   10319.45619378  .00000236  00000-0  62354-4 0  7940</tle1>
    <tle2>2 27424  98.2036 258.3378 0001264  54.1617 305.9677 14.57123781453943</tle2>
  </Satellite>
  <Satellite>
    <id>27838</id>
    <name>ORBVIEW3</name>
    <tle0>ORBVIEW 3</tle0>
    <tle1>1 27838U 03030A   10320.08123152  .00007152  00000-0  15929-3 0   425</tle1>
    <tle2>2 27838  96.9884   4.7112 0001609  66.1702  17.5471 15.43897611415052</tle2>
  </Satellite>
  <Satellite>
    <id>28931</id>
    <name>ALOS</name>
    <tle0>ALOS (DAICHI)</tle0>
    <tle1>1 28931U 06002A   10320.18010103  .00000316  00000-0  76098-4 0  3809</tle1>
    <tle2>2 28931  98.1413  32.2177 0001202  97.6884 262.4473 14.59582841256312</tle2>
  </Satellite>
  <Satellite>
    <id>31598</id>
    <name>SKYMED1</name>
    <tle0>COSMO-SKYMED 1</tle0>
    <tle1>1 31598U 07023A   10320.12036850 -.00000107  00000-0 -69111-5 0  8384</tle1>
    <tle2>2 31598  97.8612 144.9959 0001295  87.0739 273.0585 14.82168749186198</tle2>
  </Satellite>
  <Satellite>
    <id>31698</id>
    <name>TERRASAR-X</name>
    <tle0>TERRASAR-X</tle0>
    <tle1>1 31698U 07026A   10320.19654172  .00000567  00000-0  30202-4 0  8531</tle1>
    <tle2>2 31698  97.4447 325.2318 0001498  88.2507 336.5083 15.19155156189768</tle2>
  </Satellite>
  <Satellite>
    <id>32376</id>
    <name>SKYMED2</name>
    <tle0>COSMO-SKYMED 2</tle0>
    <tle1>1 32376U 07059A   10320.15411372  .00000305  00000-0  44808-4 0  2496</tle1>
    <tle2>2 32376  97.8610 145.0314 0001326  85.1830 274.9536 14.82171023158941</tle2>
  </Satellite>
  <Satellite>
    <id>32382</id>
    <name>RSAT2</name>
    <tle0>RADARSAT-2</tle0>
    <tle1>1 32382U 07061A   10320.20386927  .00000081  00000-0  48479-4 0  2364</tle1>
    <tle2>2 32382  98.5800 325.5126 0000996  92.7948 331.9613 14.29983070152587</tle2>
  </Satellite>
  <Satellite>
    <id>33412</id>
    <name>SKYMED3</name>
    <tle0>COSMO-SKYMED 3</tle0>
    <tle1>1 33412U 08054A   10320.14144199 -.00000060  00000-0 -10504-5 0  2737</tle1>
    <tle2>2 33412  97.8612 145.0178 0001265  88.0900 272.0466 14.82171643111404</tle2>
  </Satellite>
  <Satellite>
    <id>36605</id>
    <name>TANDEM-X</name>
  </Satellite>
</ArrayOfSatellite>
有什么好处?是IIS 7吗? 编辑: 这两种环境中的My web.config都有:

<httpHandlers>
  <remove verb="*" path="*.asmx"/>
  <add verb="*" path="*.asmx" type="System.Web.Script.Services.ScriptHandlerFactory" validate="false"/>
</httpHandlers>


因此生产环境应用程序使用XML而不是JSON。我会的

  • 检查两个环境是否具有相同的.NET framework版本
  • 检查生产环境中的Web.config文件是否有一行引用ScriptHandlerFactory,如:


  • 所以生产环境应用程序使用XML而不是JSON。我会的

  • 检查两个环境是否具有相同的.NET framework版本
  • 检查生产环境中的Web.config文件是否有一行引用ScriptHandlerFactory,如:


  • 听起来您的生产站点的目标是较旧的2.0 ScriptHandlerFactory。确保在IIS和中将站点设置为3.5或4.0站点


    另外,请确保您的web服务使用[ScriptService]属性装饰,而不仅仅是方法本身(实际上没有必要使用[ScriptMethod]属性)。

    听起来您的生产站点的目标是旧的2.0 ScriptHandlerFactory。确保在IIS和中将站点设置为3.5或4.0站点


    另外,请确保您的web服务使用[ScriptService]属性装饰,而不仅仅是方法本身(实际上不需要[ScriptMethod]属性)。

    升级到Server 2008R2IIS 7.5为我带来了好处

    我现在可以删除处理程序了,因为它是.NET4.0,所以不会有什么不同


    应用程序现在按预期输出JSON。我唯一做的就是升级。我什么也没做。

    升级到Server2008R2IIS7.5帮了我一把

    我现在可以删除处理程序了,因为它是.NET4.0,所以不会有什么不同


    应用程序现在按预期输出JSON。我唯一做的就是升级。我什么也没做。

    对你的两个问题都是肯定的,只是我提到的脚本工厂有点不同。。。将发布在编辑。是的,你的两个问题,除了我提到的脚本工厂是有点不同。。。将在编辑中发布。两个环境都设置了运行.NET v4.0的应用程序池,根据配置步骤,我甚至不需要脚本处理程序。因此,我尝试过使用和不使用它们,以及使用不同的版本。我确实设置了[ScriptService]属性。我将安装带有IIS 7.5的2008 R2,看看这是否有什么不同。请尝试删除服务器上的httpHandlers部分。您不需要在.NET 4中使用它,并且在没有显式版本的情况下重新定义可能会退回到ASP.NET之前的AJAX版本的程序集。是的,我尝试过,但没有任何效果。我在虚拟机中生成了7.5,它运行良好。所以我要把我的2008服务器升级到R2,看看是否能用。然而,我感觉它与服务器上的所有其他应用程序有关。某些愚蠢的mime设置或处理程序可能被继承。我们拭目以待。这两个环境都设置了一个运行.NET v4.0的应用程序池,根据配置步骤,我甚至不需要脚本处理程序。因此,我尝试过使用和不使用它们,以及使用不同的版本。我确实设置了[ScriptService]属性。我将安装带有IIS 7.5的2008 R2,看看这是否有什么不同。请尝试删除服务器上的httpHandlers部分。您不需要在.NET 4中使用它,并且在没有显式版本的情况下重新定义可能会退回到ASP.NET之前的AJAX版本的程序集。是的,我尝试过,但没有任何效果。我在虚拟机中生成了7.5,它运行良好。所以我要把我的2008服务器升级到R2,看看是否能用。然而,我感觉它与服务器上的所有其他应用程序有关。某些愚蠢的mime设置或处理程序可能被继承。我们拭目以待。
    <?xml version="1.0" encoding="utf-8"?>
    <ArrayOfSatellite xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://cstars.miami.edu/SAR">
      <Satellite>
        <id>10967</id>
        <name>SEASAT1</name>
      </Satellite>
      <Satellite>
        <id>16613</id>
        <name>SPOT1</name>
      </Satellite>
      <Satellite>
        <id>20436</id>
        <name>SPOT2</name>
        <tle0>SPOT 2</tle0>
        <tle1>1 20436U 90005A   10320.17586019  .00000436  00000-0  83185-4 0  7240</tle1>
        <tle2>2 20436  98.6342  56.4544 0155718 145.6368 215.5023 14.62070104 81087</tle2>
      </Satellite>
      <Satellite>
        <id>21574</id>
        <name>ERS1</name>
      </Satellite>
      <Satellite>
        <id>21867</id>
        <name>JERS1</name>
      </Satellite>
      <Satellite>
        <id>23560</id>
        <name>ERS2</name>
        <tle0>ERS-2</tle0>
        <tle1>1 23560U 95021A   10320.16163206  .00000093  00000-0  50826-4 0  7517</tle1>
        <tle2>2 23560  98.5539  32.9598 0001338  91.0148 269.1209 14.32246397814217</tle2>
      </Satellite>
      <Satellite>
        <id>23710</id>
        <name>RSAT1</name>
        <tle0>RADARSAT-1</tle0>
        <tle1>1 23710U 95059A   10320.17983791  .00000119  00000-0  63183-4 0  8807</tle1>
        <tle2>2 23710  98.5810 324.6746 0001101  92.8062  40.0723 14.29987468784696</tle2>
      </Satellite>
      <Satellite>
        <id>25260</id>
        <name>SPOT4</name>
        <tle0>SPOT 4</tle0>
        <tle1>1 25260U 98017A   10320.17010216  .00000053  00000-0  45000-4 0  7757</tle1>
        <tle2>2 25260  98.6410  27.5855 0001153 118.8023 241.3191 14.20071681655704</tle2>
      </Satellite>
      <Satellite>
        <id>25682</id>
        <name>LSAT7</name>
        <tle0>LANDSAT 7</tle0>
        <tle1>1 25682U 99020A   10320.17475749  .00000092  00000-0  30424-4 0  4435</tle1>
        <tle2>2 25682  98.2322  26.4024 0001343 107.7462 252.3889 14.57097903616361</tle2>
      </Satellite>
      <Satellite>
        <id>25994</id>
        <name>TERRA1</name>
        <tle0>TERRA</tle0>
        <tle1>1 25994U 99068A   10320.19170658  .00000163  00000-0  46333-4 0  3452</tle1>
        <tle2>2 25994  98.2175  32.5202 0000685  91.9171 268.2128 14.57106702580447</tle2>
      </Satellite>
      <Satellite>
        <id>27386</id>
        <name>ENVISAT1</name>
        <tle0>ENVISAT</tle0>
        <tle1>1 27386U 02009A   10320.19615002  .00000074  00000-0  39337-4 0  6231</tle1>
        <tle2>2 27386  98.5352  25.2483 0001101 100.3084 259.8244 14.37466989455514</tle2>
      </Satellite>
      <Satellite>
        <id>27421</id>
        <name>SPOT5</name>
        <tle0>SPOT 5</tle0>
        <tle1>1 27421U 02021A   10320.21390906  .00000169  00000-0  10000-3 0  6893</tle1>
        <tle2>2 27421  98.7199  32.2015 0000869  81.7846 312.1186 14.20026544442540</tle2>
      </Satellite>
      <Satellite>
        <id>27424</id>
        <name>AQUA</name>
        <tle0>AQUA</tle0>
        <tle1>1 27424U 02022A   10319.45619378  .00000236  00000-0  62354-4 0  7940</tle1>
        <tle2>2 27424  98.2036 258.3378 0001264  54.1617 305.9677 14.57123781453943</tle2>
      </Satellite>
      <Satellite>
        <id>27838</id>
        <name>ORBVIEW3</name>
        <tle0>ORBVIEW 3</tle0>
        <tle1>1 27838U 03030A   10320.08123152  .00007152  00000-0  15929-3 0   425</tle1>
        <tle2>2 27838  96.9884   4.7112 0001609  66.1702  17.5471 15.43897611415052</tle2>
      </Satellite>
      <Satellite>
        <id>28931</id>
        <name>ALOS</name>
        <tle0>ALOS (DAICHI)</tle0>
        <tle1>1 28931U 06002A   10320.18010103  .00000316  00000-0  76098-4 0  3809</tle1>
        <tle2>2 28931  98.1413  32.2177 0001202  97.6884 262.4473 14.59582841256312</tle2>
      </Satellite>
      <Satellite>
        <id>31598</id>
        <name>SKYMED1</name>
        <tle0>COSMO-SKYMED 1</tle0>
        <tle1>1 31598U 07023A   10320.12036850 -.00000107  00000-0 -69111-5 0  8384</tle1>
        <tle2>2 31598  97.8612 144.9959 0001295  87.0739 273.0585 14.82168749186198</tle2>
      </Satellite>
      <Satellite>
        <id>31698</id>
        <name>TERRASAR-X</name>
        <tle0>TERRASAR-X</tle0>
        <tle1>1 31698U 07026A   10320.19654172  .00000567  00000-0  30202-4 0  8531</tle1>
        <tle2>2 31698  97.4447 325.2318 0001498  88.2507 336.5083 15.19155156189768</tle2>
      </Satellite>
      <Satellite>
        <id>32376</id>
        <name>SKYMED2</name>
        <tle0>COSMO-SKYMED 2</tle0>
        <tle1>1 32376U 07059A   10320.15411372  .00000305  00000-0  44808-4 0  2496</tle1>
        <tle2>2 32376  97.8610 145.0314 0001326  85.1830 274.9536 14.82171023158941</tle2>
      </Satellite>
      <Satellite>
        <id>32382</id>
        <name>RSAT2</name>
        <tle0>RADARSAT-2</tle0>
        <tle1>1 32382U 07061A   10320.20386927  .00000081  00000-0  48479-4 0  2364</tle1>
        <tle2>2 32382  98.5800 325.5126 0000996  92.7948 331.9613 14.29983070152587</tle2>
      </Satellite>
      <Satellite>
        <id>33412</id>
        <name>SKYMED3</name>
        <tle0>COSMO-SKYMED 3</tle0>
        <tle1>1 33412U 08054A   10320.14144199 -.00000060  00000-0 -10504-5 0  2737</tle1>
        <tle2>2 33412  97.8612 145.0178 0001265  88.0900 272.0466 14.82171643111404</tle2>
      </Satellite>
      <Satellite>
        <id>36605</id>
        <name>TANDEM-X</name>
      </Satellite>
    </ArrayOfSatellite>
    
     var s = new System.Web.Script.Serialization.JavaScriptSerializer();
     string resultJs = s.Serialize(result);
     return resultJs;
    
    <httpHandlers>
      <remove verb="*" path="*.asmx"/>
      <add verb="*" path="*.asmx" type="System.Web.Script.Services.ScriptHandlerFactory" validate="false"/>
    </httpHandlers>