asp.net app调用服务说它没有初始化?

时间:2012-01-18 05:17:05

标签: asp.net linux mono

所以这段代码在Linux上的asp.net应用程序中运行。代码调用我的一个服务。 (WCF当前不能用于单声道,这就是我使用asmx的原因)。从Windows运行时(调试时),此代码按预期工作。一旦我部署到Linux,它就会停止工作。我当然很困惑。我已经彻底测试了服务,服务很好。

以下是产生错误的代码:( NewVisitor是一个带3个字符串的void函数)

//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();

我想知道为什么说这个对象没有设定。

尝试了方法:

  1. 新肥皂客户。
  2. 指定了绑定和端点地址的新soap客户端
  3. 使用渠道工厂创建和打开渠道。
  4. 如果需要更多信息,我可以提供更多信息。我没有想法。

2 个答案:

答案 0 :(得分:0)

不幸的是,我没有Linux来测试它,但我建议你把客户端变量放在using()语句中:

using(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);
}

我希望它有所帮助。

RC。

答案 1 :(得分:0)

它看起来像单声道中的错误。您应file a bug使用可重现的测试用例,以便可以修复(并且可能找到可以使用的解决方法)。