所以这段代码在Linux上的asp.net应用中运行。该代码调用我的一项服务。 (WCF目前不能用于单声道,这就是为什么我使用asmx)。从Windows运行时(调试时),此代码可以工作。只要我部署到Linux,它就停止工作。我很困惑。我已经彻底测试了服务,并且服务很好。asp.net应用程序调用服务说它没有初始化?
这里是产生误差的代码:(NewVisitor是服用3串中的空隙功能)
//This does not work.
try
{
var client = new Service1SoapClient();
var results = client.NewVisitor(Request.UserHostAddress, Request.UrlReferrer == null ? String.Empty : Request.UrlReferrer.ToString(), Request.UserAgent);
Logger.Debug("Result of client: " + results);
}
这里生成错误:对象引用不设置为一个对象的一个实例
这里是一个完美的作品代码:
//This works (from the service)
[WebMethod(CacheDuration = _cacheTime, Description = "Returns a List of Dates", MessageName = "GetDates")]
public List<MySqlDateTime> GetDates()
{
return db.GetDates();
}
//Here is the code for the method above
var client = new Service1Soap12Client();
var dbDates = client.GetDates();
我很想弄清楚为什么它说,对象不是组。
方法尝试:
- 新的SOAP客户端。
- 指定绑定和终点地址的新soap客户端
- 使用渠道工厂创建并打开渠道。
如果需要更多信息,我可以给予更多。我没有想法。
NullReferenceException stacktrace的顶部是否指向您的代码?确切地说哪个对象是空的? – 2012-01-18 09:51:08
var client = new Service1SoapClient();是空的对象。对我来说,这是没有意义的,因为我使用不同形式的相同代码行,并且工作正常。 – Brent 2012-01-22 10:54:32
'客户端'变量不能为空(这将违反C#规范)。可能发生的情况是,GetDates中的一些代码抛出NullReferenceException - 看到完整的堆栈跟踪会有帮助。 – 2012-01-23 12:12:25