2017-02-24 58 views
0

有没有人曾经有过在SessionModSvcContractClient注销函数抛出异常的一个问题:当我试图LogoutAsync关闭方法,他们的Epicor 10.1.5 SessionModSvcContractClient注销

Object reference not set to an instance of an object. 

:附加信息工作得很好。 任何人可以帮助我弄清楚为什么会发生的事情或3

之间的差别基本上,我试图使用从WCF引导

static void Main(string[] args) 
    { 

     //use a self-signed certificate in IIS, be sure to include the following code. This code speeds up calls to the services and prevents the method from trying to validate the certificate with the known authorities. 
     ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => { return true; }; 

     //You can toggle the value assigned to this variable to test the two bindings: SOAPHttp or BasicHttp 
     EndpointBindingType bindingType = EndpointBindingType.SOAPHttp; 

     //Epicor credentials: 
     string epicorUserID = "XXX"; 
     string epiorUserPassword = "XXX"; 


     string scheme = "http"; 
     if (bindingType == EndpointBindingType.BasicHttp) 
     { 
      scheme = "https"; 
     } 

     UriBuilder builder = new UriBuilder(scheme, "localhost"); 

     string webServicesLink = "XXX/"; 

     builder.Path = webServicesLink + "Ice/Lib/SessionMod.svc"; 
     SessionModSvcContractClient sessionModClient = GetClient < SessionModSvcContractClient, SessionModSvcContract > (builder.Uri.ToString(), epicorUserID, epiorUserPassword, bindingType); 

     builder.Path = webServicesLink + "Erp/BO/AbcCode.svc"; 
     ABCCodeSvcContractClient abcCodeClient = GetClient<ABCCodeSvcContractClient, ABCCodeSvcContract>(builder.Uri.ToString(), epicorUserID, epiorUserPassword, bindingType); 

     Guid sessionId = Guid.Empty; 
     sessionId = sessionModClient.Login(); 

     //Create a new instance of the SessionModSvc. Do this because when you call any method on the service 
     //client class, you cannot modify its Endpointbehaviors. 
     builder.Path = webServicesLink + "Ice/Lib/SessionMod.svc"; 
     sessionModClient = GetClient < SessionModSvcContractClient, SessionModSvcContract > (builder.Uri.ToString(),epicorUserID,epiorUserPassword,bindingType); 

     sessionModClient.Endpoint.EndpointBehaviors.Add(new HookServiceBehavior(sessionId, epicorUserID)); 
     abcCodeClient.Endpoint.EndpointBehaviors.Add(new HookServiceBehavior(sessionId, epicorUserID)); 

     var ts = new ABCCodeTableset(); 
     abcCodeClient.GetNewABCCode(ref ts); 
     var newRow = ts.ABCCode.Where(n => n.RowMod.Equals("A", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); 
     if (newRow != null) 
     { 
      newRow.ABCCode = "G"; 
      newRow.CountFreq = 30; 
      newRow.StockValPcnt = 100; 
      abcCodeClient.Update(ref ts); 
      ts = null; 
      ts = abcCodeClient.GetByID("G"); 
      if (ts != null && ts.ABCCode.Any()) 
      { 
       ABCCodeRow backupRow = new ABCCodeRow(); 
       var fields = backupRow.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); 
       foreach (var field in fields) 
       { 
        if (field.PropertyType == typeof(System.Runtime.Serialization.ExtensionDataObject)) 
        { 
         continue; 
        } 
        var fieldValue = field.GetValue(ts.ABCCode[0]); 
        field.SetValue(backupRow, fieldValue); 
       } 
       ts.ABCCode.Add(backupRow); 
       ts.ABCCode[0].CountFreq = 45; 
       ts.ABCCode[0].RowMod = "U"; 
       abcCodeClient.Update(ref ts); 
       ts = null; 
       ts = abcCodeClient.GetByID("G"); 
       if (ts != null && ts.ABCCode.Any()) 
       { 
        Console.WriteLine("CountFreq = {0}", ts.ABCCode[0].CountFreq); 
        ts.ABCCode[0].RowMod = "D"; 
        abcCodeClient.Update(ref ts); 
        try 
        { 
         ts = abcCodeClient.GetByID("G"); 
        } 
        catch (FaultException<Epicor.AbcCodeSvc.EpicorFaultDetail> ex) 
        { 
         if (ex.Detail.ExceptionKindValue.Equals("RecordNotFound", StringComparison.InvariantCultureIgnoreCase)) 
         { 
          Console.WriteLine("Record deleted."); 
         } 
         else 
         { 
          Console.WriteLine(ex.Message); 
         } 
        } 
       } 
      } 
     } 
     if (sessionId != Guid.Empty) 
     { 

       sessionModClient.Logout(); 


     } 
     Console.ReadLine(); 
    } 
+1

请包括您的代码,这是一个标准的NullReferenceException,并有多种原因。请参阅:http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it –

+0

我基本上尝试从WCF示例代码 – yahyazini

回答

1

看我其他的答案创建测试,但作为一个另外你可能想考虑这种访问服务的方法。

如果你有机会到客户端的DLL那么这段代码可能会更容易:

static void Main(string[] args) 
    { 
     // Hard-coded LogOn method 
     // Reference: Ice.Core.Session.dll 
     Ice.Core.Session session = new Ice.Core.Session("manager", "manager", "net.tcp://AppServer/MyCustomerAppserver-99999-10.0.700.2"); 

     // References: Epicor.ServiceModel.dll, Erp.Contracts.BO.ABCCode.dll 
     var abcCodeBO = Ice.Lib.Framework.WCFServiceSupport.CreateImpl<Erp.Proxy.BO.ABCCodeImpl>(session, Erp.Proxy.BO.ABCCodeImpl.UriPath); 

     // Call the BO methods 
     var ds = abcCodeBO.GetByID("A"); 
     var row = ds.ABCCode[0]; 

     System.Console.WriteLine("CountFreq is {0}", row.CountFreq); 
     System.Console.ReadKey(); 
    } 

只需添加引用:

  • Ice.Core.Session.dll
  • Epicor.ServiceModel .dll
  • Erp.Contracts.BO.ABCCode.dll
+0

对不起我的错误close调用刚刚添加时,我正在调试我只是更新代码,并删除了close方法调用,并用注销取代它,因为这正是我目前正在尝试做的。 – yahyazini

+1

了解,我设法复制您的问题,但不是与您的代码,请参阅我的其他答案。我会让这个答案成为访问Web服务的替代方法。 –

1

我更改了配置以适合我的环境后,您的代码对我来说工作得很好。

它看起来像您遵循Epicor10_techrefWCFServices_101400.pdf指南的第15页上的步骤7,并在Login()后正确创建SessionModSvc的新实例。但是,如果您从第18页复制了Main方法的完整代码,那么这是缺少的,我可以复制您的问题。

在致电.Login()后,检查您正在编译的代码是否创建了SessionModSvc的新实例。

+0

我刚刚复制了您指向的相同代码,但它抛出了相同的异常。此外,我在10.1.500版本,我认为你在10.1.400? – yahyazini