Reputation: 461
UPDATE SEND TO VDWWD who close my question.Please pay attention and read my question completly before making your decision. My code exception in 'new x();' initialize constructor? and it not jump inside initialize constructor function. I tried every thing i can, and I'm sure that my problem is not resolved in https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it
I got a big problem with my project. I used SOAP to call SMSBRANDNAME API:
Controller:
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()
};
}
Function in 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;
............
I got this exception:
{System.NullReferenceException: Object reference not set to an instance of an object. at System.Web.Services.Protocols.SoapClientType..ctor(Type type) at System.Web.Services.Protocols.SoapHttpClientProtocol..ctor() at BulkApi..ctor() in E:\Project\HtxThienHuong\HTXThienHuong\Services\BulkAPI\BulkApi.cs:line 25 at BulkApp.BulkSMS.SendSMS(BulkDto sender) in E:\Project\HtxThienHuong\HTXThienHuong\Services\BulkAPI\BulkSMS.cs:line 47}
I don't know how to fix it and why it wrong, please save me. Thank you all!
Upvotes: 0
Views: 561