1

有没有人遇到过SessionModSvcContractClient Logout函数抛出异常的问题:附加信息:

Object reference not set to an instance of an object.

当我尝试LogoutAsyncClose方法时,它们运行良好。任何人都可以帮我弄清楚为什么会发生这种情况或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();
    }
4

2 回答 2

1

在我更改配置以适应我的环境后,您的代码对我来说很好。

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

检查您正在编译的代码在调用.Login().

于 2017-03-01T10:11:59.350 回答
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
于 2017-02-27T16:27:57.247 回答