0

更新发送给关闭我的问题的 VDWWD。在做出决定之前,请注意并完整阅读我的问题。我在'new x();'中的代码异常 初始化构造函数?它不会跳入初始化构造函数。我尽我所能,我确信我的问题没有解决https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it

我的项目遇到了一个大问题。我使用 SOAP 调用 SMSBRANDNAME API:

控制器:

try
{
  string phone = sender.phone;
  string smsContent = sender.smsContent;
  string username = sender.username;
  string password = sender.password;
  string cpCode = sender.cpCode;
  string serviceID = sender.serviceID;
  string commandCode = sender.commandCode;
  BulkApi api = new BulkApi();<<<== **CODE THROW EXCEPTION HERE**
  api.Timeout = 6000;
  result r = api.wsCpMt(username, password, cpCode, "1", phone, phone, serviceID, commandCode, smsContent, "F");

  if (r.result1 == 1)
  {
      return new SMSResult()
      {
          status = "success",
          message = "Gửi tin thành công!",
          errorCode = r.message
      };
  }
  else
  {
      return new SMSResult()
      {
          status = "fail",
          message = "Gửi tin thất bại!",
          errorCode = r.message
      };
  }
}
catch (Exception ex)<<<== **I GOT EXCEPTION HERE**
{
  return new SMSResult()
  {
      status = "error",
      message = "Đã có lỗi xảy ra!",
      errorCode = ex.ToString()
  }; 
}   

BulkAPI.cs 中的函数:

[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="CcApiPortBinding", Namespace="http://impl.bulkSms.ws/")]
public class BulkApi : System.Web.Services.Protocols.SoapHttpClientProtocol
{

  private System.Threading.SendOrPostCallback getIpOperationCompleted;

  private System.Threading.SendOrPostCallback checkBalanceOperationCompleted;

  private System.Threading.SendOrPostCallback wsCpMtOperationCompleted;

  private System.Threading.SendOrPostCallback wsReportHourOperationCompleted;

  private System.Threading.SendOrPostCallback wsReportDailyOperationCompleted;

  private System.Threading.SendOrPostCallback wsReportMonthOperationCompleted;

  private System.Threading.SendOrPostCallback getFailSubOperationCompleted;


  public BulkApi()
  {               <<<<= **I PUT BREAK POINT HERE BUT CODE NO JUMP IN**
      this.Url = "https://ams.tinnhanthuonghieu.vn:8998/bulkapi?wsdl";
  }

  public event getIpCompletedEventHandler getIpCompleted;


  public event checkBalanceCompletedEventHandler checkBalanceCompleted;


  public event wsCpMtCompletedEventHandler wsCpMtCompleted;

  ............

我得到了这个例外:

{System.NullReferenceException:对象引用未设置为对象的实例。在 System.Web.Services.Protocols.SoapClientType..ctor(Type type) 在 System.Web.Services.Protocols.SoapHttpClientProtocol..ctor() 在 BulkApi..ctor() 在 E:\Project\HtxThienHuong\HTXThienHuong\Services \BulkAPI\BulkApi.cs:第 25 行 BulkApp.BulkSMS.SendSMS(BulkDto sender) 在 E:\Project\HtxThienHuong\HTXThienHuong\Services\BulkAPI\BulkSMS.cs:line 47}

我不知道如何解决它,为什么它错了,请救救我。谢谢你们!

4

0 回答 0