簡體   English   中英

Asp.Net Asmx Web服務方法在localhost中運行,但是服務器中出現錯誤

[英]Asp.Net Asmx Webservice Method working in localhost but i am getting error in Server

我有ASMX網絡服務,我想以JSON格式返回結果。 它在本地主機上工作正常,但在服務器上不工作。

在服務器中,我正在獲取對象引用未設置為對象錯誤的實例。 我是這個新手,請幫我解決這個錯誤

 [WebService(Namespace = "http://DomainNameHere/Mymis")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class PMIS_WebService : System.Web.Services.WebService
    {
        //private string cs = ConfigurationManager.ConnectionStrings["ConnectionName"].ConnectionString;
        [WebMethod]
        public void getCapacityBuildings()
        {
            string cs = ConfigurationManager.ConnectionStrings["ConnectionName"].ConnectionString;
            List<CapacityBuildingbel> Trainingss = new List<CapacityBuildingbel>();
            using (SqlConnection con = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand("spGetTrainingsCapacityBuilding", con);
                cmd.CommandType = CommandType.StoredProcedure;
                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    CapacityBuildingbel Trainings = new CapacityBuildingbel();
                    Trainings.train_program = rdr["Train_Program"].ToString();
                    Trainings.wucs_covered = rdr["WUCS_Covered"].ToString();
                    Trainings.venue = rdr["Venue"].ToString();
                    Trainings.Train_date = Convert.ToDateTime(rdr["date"]);
                    Trainings.Female = Convert.ToInt32(rdr["female"]);
                    Trainings.Male = Convert.ToInt32(rdr["male"]);
                    Trainings.theme = rdr["Theme"].ToString();
                    Trainings.remarks = rdr["Remarks"].ToString();
                    Trainingss.Add(Trainings);
                }
                con.Close();
            }
            JavaScriptSerializer js = new JavaScriptSerializer();
            Context.Response.Write(js.Serialize(Trainingss));
        }

我正在得到的錯誤 在此處輸入圖片說明 我的WebConfig文件

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
   <connectionStrings>
    <add name="ConnectionName"  connectionString="Data Source=MyDATASOURCE;Initial Catalog=USERNAME;user id=PASSWORD; password=PASSWORD;" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
   <machineKey 
validationKey="D2880E1DCEAC1601B850B247A4385706029F918E90240FA15F98FD1ABCF0E0298E6460B571B06A392B86D0E41773E35BC84096897171C6984FD5D0BA8A6F4AF0"
decryptionKey="7281B4835FB1DC371EC9945A5208CF987EEEE06D04E15A0264B6F3CA12C764B7"
validation="SHA1" decryption="AES"/>
  <customErrors mode="Off" defaultRedirect="apperror.aspx">
          <error statusCode="404" redirect="404.aspx" />
          <error statusCode="500" redirect="500.aspx" />
    </customErrors>

<httpCookies httpOnlyCookies="false" requireSSL="false"/>
<sessionState timeout="20" mode="StateServer">
</sessionState>
    <pages>
      <controls>
        <add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        <add tagPrefix="asp" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" />
      </controls>
    </pages>
    <httpHandlers>
      <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" validate="false"/>
      <add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
    </httpHandlers>
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        <add assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
        <add assembly="Microsoft.ReportViewer.Common, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
        <add assembly="Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </assemblies>
      <buildProviders>
        <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
      </buildProviders>
    </compilation>
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
    <add key="ChartImageHandler" value="storage=memory;timeout=20;"/>
  </appSettings>
  <system.webServer>
      <defaultDocument enabled="true">
 <files>
    <clear/>
    <add value="Login.aspx"/>
 </files>
</defaultDocument>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
      <remove name="ChartImageHandler"/>
      <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
      <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </handlers>
    <!--<directoryBrowse enabled="true"/>-->
  </system.webServer>
</configuration>

經過大量的搜索,我找到了解決此問題的方法,問題不在於Web服務器的代碼。 即,您需要啟動ASP.NET狀態服務服務並將其更改為在服務器中自動啟動,然后它將可以正常工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM