NET Web服务不返回JSON数据了 [英] .NET Webservice doesn't return JSON data anymore

查看:160
本文介绍了NET Web服务不返回JSON数据了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近几个月我一直忙于创建一个.NET web服务具有多种功​​能,并写在HTML网站和Javascript充当用户界面,并调用Web服务方法使用JSON。该web服务返回的JSON响应,它没有很好地工作。然后,我集中在Web服务来完成所有的功能,并没有打开网页约3周。

Last months I've been busy creating a .NET Webservice with several functions and a website written in html and Javascript which acts as the user interface and calls the webservice methods with JSON. The webservice returned JSON responses and it did work very well. Then I concentrated on the webservice to finish all the functionality and didn't open the website for about 3 weeks.

今天我完成了Web服务,并决定继续在网站上的工作。但是,当我打开一看,我发现了JSON通信不工作了......

Today I finished the webservice and decided to continue the work on the website. But when I opened it, I found the JSON communication not working anymore...

该网站仍然发送的JSON请求(与网络嗅探器经过了这一点),但web服务不再响应,所以它必须对Web服务端的一个问题。

The website still sends the JSON requests (Checked this with a network sniffer) but the webservice doesn't respond anymore, so it has to be a problem on the webservice side.

我试图找到问题这整整一天,却找不到任何东西.. 这里是一些code段,这可能是有用的。

I am trying to find the problem this whole day, but can't find anything.. Here some code snippets which might be usefull

WebService的标题:

The webservice headers:

 [WebService(Namespace = "http://meijberg.topicus.local/zdfmobiel")]
 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
 [ScriptService]
 [System.ComponentModel.ToolboxItem(false)]

 public class ZDFMobielWebservice : WebService {

Web.config文件

The Web.Config file

<?xml version="1.0"?>
<configuration>
    <configSections>
    	<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    		<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    			<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    			<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    				<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
    				<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    				<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    				<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    			</sectionGroup>
    		</sectionGroup>
    	</sectionGroup>
    <sectionGroup name="declaratieverwerking">
      <section name="db" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      <section name="msmq" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
    </sectionGroup>
    <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
      <section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core"/>
    </sectionGroup>
    </configSections>



  <declaratieverwerking>
    <db>
      <add key="datasource" value="CARTMAN"/>
      <add key="database" value="DV_TRUNK"/>
      <add key="user" value="****"/>
      <add key="password" value="****"/>
      <add key="applicationName" value="DeclaratieVerwerking.WebApplication"/>
    </db>
    <msmq>
      <add key="DeclaratieRegelHA304Queue" value=".\Private$\DV_DeclaratieRegelHA304Queue"/>
      <add key="DeclaratieRegelAP304Queue" value=".\Private$\DV_DeclaratieRegelAP304Queue"/>
      <add key="DeclaratieRegelZH308Queue" value=".\Private$\DV_DeclaratieRegelZH308Queue"/>
      <add key="DeclaratieBerichtHA304Queue" value=".\Private$\DV_DeclaratieBerichtHA304Queue"/>
      <add key="DeclaratieBerichtAP304Queue" value=".\Private$\DV_DeclaratieBerichtAP304Queue"/>
      <add key="DeclaratieBerichtZH308Queue" value=".\Private$\DV_DeclaratieBerichtZH308Queue"/>
      <add key="ErrorQueue" value=".\Private$\DV_ErrorQueue"/>
    </msmq>
  </declaratieverwerking>


  <appSettings>
    <add key="RecreateHibernateMapping" value="True"/>
    <add key="UseUpdateSchema" value="True"/>
  </appSettings>

  <connectionStrings/>

  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="AjaxEndpointBehavior">
          <enableWebScript/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <services>
      <service name="ZDFMobiel.Webservice.ZDFMobielWebservice">
        <endpoint adress=""
          behaviorConfiguration="AspNetAjaxBehavior"
          binding="webHttpBinding"
          contract="ZDFMobiel.Webservice.ZDFMobielWebservice" />
      </service>
    </services>
  </system.serviceModel>

  <spring>
    <context>
      <resource uri="~/Config/Spring.config"/>
    </context>
    <parsers>
      <parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data"/>
      <parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data"/>
    </parsers>
  </spring>


  <system.web>

    <webServices>
      <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
      </protocols>
    </webServices>    

    	<compilation debug="true">
    		<assemblies>
    			<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    			<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    			<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    		</assemblies>
    	</compilation>

    	<authentication mode="Windows"/>

    	<pages>
    		<controls>
    			<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    		</controls>
      <namespaces>
        <add namespace="Declaratieverwerking.WebApplication.Beheer.Controllers"/>
        <add namespace="Declaratieverwerking.WebApplication.Workspace.Controllers"/>
      </namespaces>
    	</pages>
    	<httpHandlers>     
    		<remove verb="*" path="*.asmx"/>
    		<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    		<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    		<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
    	</httpHandlers>
    	<httpModules>
      <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
      <add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate"/>
    		<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    	</httpModules>
        <trust level="Full"/>
        <identity impersonate="true" password="*******" userName="Administrator"/>
    </system.web>

    <system.codedom>
    	<compilers>
    		<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    			<providerOption name="CompilerVersion" value="v3.5"/>
    			<providerOption name="WarnAsError" value="false"/>
    		</compiler>
    	</compilers>
    </system.codedom>
    <!-- 
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    -->
    <system.webServer>
    	<validation validateIntegratedModeConfiguration="false"/>
    	<modules runAllManagedModulesForAllRequests="true">
    		<remove name="ScriptModule"/>
    		<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
      <add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate"/>
    	</modules>
    	<handlers>
    		<remove name="WebServiceHandlerFactory-Integrated"/>
    		<remove name="ScriptHandlerFactory"/>
    		<remove name="ScriptHandlerFactoryAppServices"/>
    		<remove name="ScriptResource"/>
    		<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    		<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    		<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    	</handlers>
        <httpRedirect enabled="false" destination="http://www.google.nl"/>
    </system.webServer>
    <runtime>
    	<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    		<dependentAssembly>
    			<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
    			<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
    		</dependentAssembly>
    		<dependentAssembly>
    			<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
    			<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
    		</dependentAssembly>
    	<dependentAssembly>
    			<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
    			<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
    		</dependentAssembly> 

      <dependentAssembly>
        <assemblyIdentity name="Spring.Core" publicKeyToken="65E474D141E25E07" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-1.3.0.20214" newVersion="1.3.0.20214"/>
      </dependentAssembly>
    	</assemblyBinding>
    </runtime>
</configuration>

编辑:有些客户方的javascript code的调用webservice的:

Some clientside javascript code which call the webservice:

		var xhrGegevens = new XMLHttpRequest();
		xhrGegevens.open("POST", "http://meijberg.topicus.local/ZDFMobielWebservice.asmx/getGegevensVerzekerde", true);
		xhrGegevens.onreadystatechange = function(){

			if (xhrGegevens.readyState === 4) {

				var result = eval('(' + xhrGegevens.responseText + ')');

				//Functionality
			}

		}
		xhrGegevens.setRequestHeader("content-type", "application/json");
		var postData = '{"bsn": "999999999"}';
		xhrGegevens.send(postData);

编辑:getGevensVerzekerde方法的web服务:

The getGevensVerzekerde Method in the webservice:

[WebMethod]
public VerzekerdeGegevens getGegevensVerzekerde(string bsn)
{
    ZorgVerzekerde verzekerde = Dao.GetVerzekerde(Convert.ToInt32(bsn));
    VerzekerdeGegevens result = new VerzekerdeGegevens();

    result.bsn = verzekerde.Bsn;
    result.geboortedatum = verzekerde.Geboortedatum.Value.ToShortDateString();
    result.geslacht = Convert.ToString(verzekerde.Geslacht);
    result.huisnummer = verzekerde.Huisnummer;
    result.naam = verzekerde.Naam;
    result.postcode = verzekerde.Postcode;
    result.voorletters = verzekerde.Voorletters;

    int i = 0;

    foreach(ZorgPolisInstantie polisInstantie in verzekerde.PolisInstanties)
    {
        PolisGegevens gegevens = new PolisGegevens();

        gegevens.begindatum = polisInstantie.Begindatum.ToShortDateString();
        gegevens.einddatum = polisInstantie.Einddatum.Value.ToShortDateString();
        if(polisInstantie.Type == (ZorgPolisInstantie.ZorgPolisType) 1)
        {
            gegevens.eigenrisico = polisInstantie.EigenRisico;
        }
        else { gegevens.eigenrisico = 0; }

        gegevens.polisnummer = Convert.ToString(polisInstantie.PolisNummer);
        gegevens.type = (int) polisInstantie.Type;
        result.polisgegevens.Add(gegevens);     
    }
    return result;
}

任何谁知道是什么问题呢?

Anyone who knows what the problem might be?

推荐答案

您从您的Web服务方法缺少以下属性:?

Are you missing the following attributes from your web service methods?:

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

此外,当您使用相对URL会发生什么,如:

Also what happens when you use a relative URL, i.e.:

xhrGegevens.open("POST", "ZDFMobielWebservice.asmx/getGegevensVerzekerde", true);

这篇关于NET Web服务不返回JSON数据了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆