Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Epicor 10.1.5 SessionModSvcContractClient注销_C#_Epicorerp_Epicor_Epicor10 - Fatal编程技术网

C# Epicor 10.1.5 SessionModSvcContractClient注销

C# Epicor 10.1.5 SessionModSvcContractClient注销,c#,epicorerp,epicor,epicor10,C#,Epicorerp,Epicor,Epicor10,是否有人曾经遇到过这样的问题,即SessionModSvcContractClient注销功能引发异常:其他信息: Object reference not set to an instance of an object. 当我尝试LogoutAsync和Close方法时,它们工作得很好。 有谁能帮我弄清楚为什么会这样,或者三者之间的区别 我基本上是在尝试使用WCF指南创建测试 static void Main(string[] args) { //use a

是否有人曾经遇到过这样的问题,即SessionModSvcContractClient注销功能引发异常:其他信息:

Object reference not set to an instance of an object.
当我尝试LogoutAsyncClose方法时,它们工作得很好。 有谁能帮我弄清楚为什么会这样,或者三者之间的区别

我基本上是在尝试使用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();
    }
static void Main(字符串[]args)
{
//在IIS中使用自签名证书,请确保包含以下代码。此代码加快对服务的调用,并防止该方法尝试使用已知权限验证证书。
ServicePointManager.ServerCertificateValidationCallback+=(发送方、证书、链、错误)=>{return true;};
//您可以切换分配给此变量的值以测试两个绑定:SOAPHttp或BasicHttp
EndpointBindingType bindingType=EndpointBindingType.SOAPHttp;
//Epicor证书:
字符串epicorUserID=“XXX”;
字符串epiorUserPassword=“XXX”;
string scheme=“http”;
if(bindingType==EndpointBindingType.BasicHttp)
{
scheme=“https”;
}
UriBuilder=新的UriBuilder(方案,“本地主机”);
字符串webServicesLink=“XXX/”;
builder.Path=webServicesLink+“Ice/Lib/SessionMod.svc”;
SessionModSvcContractClient sessionModClient=GetClient(builder.Uri.ToString(),epicorUserID,EpicorUserPassword,bindingType);
builder.Path=webServicesLink+“Erp/BO/AbcCode.svc”;
ABCCodeSvcContractClient=GetClient(builder.Uri.ToString(),epicorUserID,EpicorUserPassword,bindingType);
Guid sessionId=Guid.Empty;
sessionId=sessionModClient.Login();
//创建SessionModSvc的新实例。这样做是因为在调用服务上的任何方法时
//客户端类,不能修改其端点行为。
builder.Path=webServicesLink+“Ice/Lib/SessionMod.svc”;
sessionModClient=GetClient(builder.Uri.ToString(),epicorUserID,EpicorUserPassword,bindingType);
添加(新的HookServiceBehavior(sessionId,epicorUserID));
abcCodeClient.Endpoint.EndpointBehaviors.Add(新的HookServiceBehavior(sessionId,epicorUserID));
var ts=新的ABCCodeTableset();
abcCodeClient.GetNewABCCode(参考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.更新(参考ts);
ts=null;
ts=abcCodeClient.GetByID(“G”);
如果(ts!=null&&ts.ABCCode.Any())
{
ABCCodeRow backupRow=新的ABCCodeRow();
var fields=backupRow.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
foreach(字段中的变量字段)
{
if(field.PropertyType==typeof(System.Runtime.Serialization.ExtensionDataObject))
{ 
继续;
}
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.更新(参考ts);
ts=null;
ts=abcCodeClient.GetByID(“G”);
如果(ts!=null&&ts.ABCCode.Any())
{
WriteLine(“CountFreq={0}”,ts.ABCCode[0].CountFreq);
ts.ABCCode[0].RowMod=“D”;
abcCodeClient.更新(参考ts);
尝试
{
ts=abcCodeClient.GetByID(“G”);
}
捕获(FaultException-ex)
{
if(例如Detail.ExceptionKindValue.Equals(“RecordNotFound”,StringComparison.InvariantCultureIgnoreCase))
{
Console.WriteLine(“记录已删除”);
}
其他的
{
控制台写入线(例如消息);
}
}
}
}
}
if(sessionId!=Guid.Empty)
{
sessionModClient.Logout();
}
Console.ReadLine();
}

< /代码> 见我的另一个答案,但作为另一种选择,您可能需要考虑访问服务的方法。 如果您可以访问客户端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();
    }
static void Main(字符串[]args)
{
//硬编码登录方法
//参考:Ice.Core.Session.dll
Ice.Core.Session Session=新的Ice.Core.Session(“管理器”、“管理器”、“网络”)。tcp://AppServer/MyCustomerAppserver-99999-10.0.700.2");
//参考:Epicor.ServiceModel.dll、Erp.Contracts.BO.ABCCode.dll
var abcCodeBO=Ice.Lib.Framework.WCFServiceSupport.CreateImpl(会话,Erp.Proxy.BO.ABCCodeImpl.UriPath);
//调用BO方法
var ds=abcCodeBO.GetByID(“A”);
var row=ds.ABCCode[0];
System.Console.WriteLine(“CountFreq是{0}”,row.CountFreq);
System.Console.ReadKey();
}
只需添加对以下内容的引用:

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

在我更改配置以适应您的需要后,您的代码对我来说运行良好