2017-02-24 5 views
0

Hat jemand schon einmal ein Problem, wo die SessionModSvcContractClientLogout Funktion löst eine Ausnahme aus: Weitere Informationen:Epicor 10.1.5 SessionModSvcContractClient abzumelden

Object reference not set to an instance of an object. 

Als ich versuchte, LogoutAsync und Schließen Methoden, die sie hat gut funktioniert. Kann jemand mir helfen, herauszufinden, warum das passiert oder die Differenz zwischen den 3.

Ich bin im Grunde den Test aus der WCF Führung

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

Bitte fügen Sie Ihren Code ein, dies ist eine Standard NullReferenceException und hat eine Vielzahl von Ursachen. Siehe: http://StackOverflow.com/Questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it –

+0

Ich versuche grundsätzlich den Code aus dem WCF-Beispiel – yahyazini

Antwort

1

Sehen Sie meine andere Antwort, aber als zu verwenden, erstellen Sie versuchen, Alternativ können Sie diese Methode des Zugriffs auf die Dienste betrachten.

Wenn Sie Zugriff auf den Client-DLLs haben, dann könnte dieser Code einfacher sein:

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

Nur Referenzen hinzufügen:

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

Sorry mein Fehler, dass close call wurde nur hinzugefügt, als ich debugging Ich habe nur den Code aktualisiert und den Aufruf der close-Methode entfernt und ihn durch logout ersetzt, weil ich das gerade versuche. – yahyazini

+1

Verstanden, ich habe es geschafft, Ihr Problem zu replizieren, aber nicht mit Ihrem Code, siehe meine andere Antwort. Ich lasse diese Antwort stehen, da es sich um eine alternative Methode zum Zugriff auf die Webdienste handelt. –

1

Ihr Code funktionierte gut für mich, nachdem ich die Konfiguration an meine Umgebung angepasst hatte.

Es sieht so aus, als ob Sie den Schritt 7 auf Seite 15 des Handbuchs Epicor10_techrefWCFServices_101400.pdf befolgt und nach Login() eine neue Instanz von SessionModSvc ordnungsgemäß erstellt haben. Wenn Sie jedoch den vollständigen Code für die Main-Methode von Seite 18 kopiert haben, fehlt dieser Code und ich kann Ihr Problem replizieren.

Überprüfen Sie, ob der kompilierte Code nach dem Aufruf von .Login() eine neue Instanz von SessionModSvc erstellt hat.

+0

Ich habe nur den gleichen Code kopiert, auf den Sie verwiesen haben, aber es wurde dieselbe Ausnahme ausgelöst. Auch ich bin auf Version 10.1.500 und ich denke du bist auf 10.1.400? – yahyazini

Verwandte Themen