具体出现问题代码在236行
#ifndef _ISTA_AIR_SERVICE_CLIENT_H
#define _ISTA_AIR_SERVICE_CLIENT_H
#include"myhead.h"
//public abstract 服务客户端模板抽象类基类
template<typename TServiceContract>
class IstaServiceClientBase //:public IDisposable
{
// Token: 0x04000002 RID: 2
private:
ChannelFactory<TServiceContract> channelFactory; //工厂
protected:
IstaServiceClientBase(ChannelFactory<TServiceContract> channelFactory)
{
this->channelFactory = channelFactory;
}
public:
void Dispose()
{
this->channelFactory.Close();
}
private:
static void CloseChannel(TServiceContract channel)
{
ICommunicationObject communicationObject = channel as ICommunicationObject;
if (communicationObject == null)
{
return;
}
if (communicationObject.State == CommunicationState.Faulted)
{
communicationObject.Abort();
return;
}
communicationObject.Close();
}
protected:
//void CallAction(Action<TServiceContract> action)
void CallAction(void(*action(TServiceContract)))
{
TServiceContract tserviceContract = default(TServiceContract);
try
{
tserviceContract = this->channelFactory.CreateChannel();
action(tserviceContract);
}
catch (FaultException<TServiceContract>)
{
throw;
}
catch (FaultException<FbmTransferException>)
{
throw;
}
catch (FaultException arg)
{
Console.WriteLine("{0}", arg);
throw;
}
catch (Exception)
{
throw;
}
finally
{
IstaServiceClientBase<TServiceContract>.CloseChannel(tserviceContract);
}
}
//TResult CallFunction<TResult>(Func<TServiceContract, TResult> func)
template<typename TResult>
TResult CallFunction(TResult&func(TServiceContract))
{
TServiceContract tserviceContract = default(TServiceContract);
TResult result;
try
{
tserviceContract = this->channelFactory.CreateChannel();
result = func(tserviceContract);
}
catch (FaultException<TServiceContract>)
{
throw;
}
catch (FaultException arg)
{
Console.WriteLine("{0}", arg);
throw;
}
catch (Exception)
{
throw;
}
finally
{
IstaServiceClientBase<TServiceContract>.CloseChannel(tserviceContract);
}
return result;
}
//async Task CallFunctionAsync(Func<TServiceContract, Task> func)
Task CallFunctionAsync(Task &func(TServiceContract))
{
TServiceContract channel = default(TServiceContract);
try
{
channel = this.channelFactory.CreateChannel();
await func(channel);
}
catch (FaultException arg)
{
Console.WriteLine("{0}", arg);
throw;
}
catch (Exception)
{
throw;
}
finally
{
IstaServiceClientBase<TServiceContract>.CloseChannel(channel);
}
}
//async Task<TResult> CallFunctionAsync<TResult>(Func<TServiceContract, Task<TResult>> func)
template<typename Tresult>
Task<TResult> CallFunctionAsync(Task<TResult>& func(TServiceContract))
{
TServiceContract channel = default(TServiceContract);
TResult result;
try
{
channel = this->channelFactory.CreateChannel();
result = await func(channel);
}
catch (FaultException arg)
{
Console.WriteLine("{0}", arg);
throw;
}
catch (Exception)
{
throw;
}
finally
{
IstaServiceClientBase<TServiceContract>.CloseChannel(channel);
}
return result;
}
ChannelFactory<TServiceContract> get_ChannelFactory()
{
return this->channelFactory;
}
};
//public abstract 服务客户端模板抽象类
template<typename TServiceContract>
class IstaServiceClient :public IstaServiceClientBase<TServiceContract>, public IIstaService //, IIstaService where TServiceContract : IIstaService
{
protected:
//子类构造顺便调用基类的有参构造
IstaServiceClient():IstaServiceClientBase<TServiceContract>(this->CreateChannelFactory())
{
}
private:
static ChannelFactory<TServiceContract> CreateChannelFactory()
{
NetNamedPipeBinding binding = new NetNamedPipeBinding
{
ReceiveTimeout = TimeSpan.MaxValue,
SendTimeout = TimeSpan.MaxValue,
MaxReceivedMessageSize = 2147483647L
};
EndpointAddress remoteAddress = new EndpointAddress(new Uri(string.Format(CultureInfo.InvariantCulture
, "net.pipe://localhost/IstaServicesHost/{0}", typeof(TServiceContract).Name)), new AddressHeader[]
{AddressHeader.CreateAddressHeader("PID", string.Empty, Process.GetCurrentProcess().Id.ToString())});
return ChannelFactory<TServiceContract>(binding, remoteAddress);
}
public:
template<typename TResult>
TResult IstaServiceClientBase<TServiceContract>:: CallFunction(TResult& func(TServiceContract));
bool IsAvailable_fun(TServiceContract channel)
{
return channel.IsAvailable();
}
template<typename TResult>
bool IsAvailable()
{
bool result = this->CallFunction<bool>(IsAvailable_fun);
//try
//{
// result = this->CallFunction<bool>((TServiceContract channel) = > channel.IsAvailable());
//}
//catch (Exception)
//{
// result = false;
//}
return result;
}
};
//template<typename TServiceContract>
class IstaAirServiceClient :public IstaServiceClient<IIstaAirService>, public IIstaAirService, public IIstaService
{
private:
AirStartProperties fun_props;//StartAir调用的委托需要的变量
string fun_vin7, fun_string_0, fun_lang;//TeileClearingRelevant调用的委托需要的变量
AirSendMaintenanceEntry fun_entry;
string fun_string_1;
public:
//子类构造顺便调用基类的有参构造
//IstaAirServiceClient() :IstaServiceClient<IIstaAirService>()
//{
//}
//template<typename TServiceContract>
//bool IstaServiceClient<IIstaAirService>::IsAvailable();
//template<typename TResult>
bool IstaServiceClient<IIstaAirService>::IsAvailable();
//下面函数StartAir用了Lambda表达式,委托为CallFunction的参数::TResult& func(TServiceContract) 其中TResult是模板类型
AirStartResponse StartAir_fun(IIstaAirService channel)//StartAir调用的委托方法。
{
return channel.StartAir(fun_props);
}
template<typename TResult>
AirStartResponse StartAir(AirStartProperties props)
{
this->fun_props = props;//用来给委托方法的返回值用。
//return base.CallFunction<AirStartResponse>((IIstaAirService channel) = > channel.StartAir(props));
return this->CallFunction<AirStartResponse>(StartAir_fun);//调用了委托方法
}
bool TeileClearingRelevant_fun(IIstaAirService channel)//TeileClearingRelevant调用的委托方法
{
return channel.TeileClearingRelevant(fun_vin7, fun_string_0, fun_lang);
}
template<typename TResult>
bool TeileClearingRelevant(string vin7, string string_0, string lang)
{
fun_vin7 = vin7; fun_string_0 = string_0; fun_lang = lang;//给调用的委托方法返回值用。
return this->CallFunction<bool>(TeileClearingRelevant_fun);//调用了委托方法。
}
AirSendMaintenanceEntryResponse SendMaintenanceEntry_fun(IIstaAirService channel)
{
return channel.SendMaintenanceEntry(fun_entry);
}
template<typename TResult>
AirSendMaintenanceEntryResponse SendMaintenanceEntry(AirSendMaintenanceEntry entry)
{
fun_entry = entry;
return this->CallFunction<AirSendMaintenanceEntryResponse>(SendMaintenanceEntry_fun);
}
AirServiceHistoryLP2Response GetServiceHistoryLP2_fun(IIstaAirService channel)
{
return channel.GetServiceHistoryLP2(fun_string_1);
}
template<typename TResult>
AirServiceHistoryLP2Response GetServiceHistoryLP2(string string_0)
{
fun_string_1 = string_0;
return this->CallFunction<AirServiceHistoryLP2Response>(GetServiceHistoryLP2_fun);
}
};
//-----------------namespace BMW.ISPI.IstaServices.Contract.AIR------------//
//
//航空发送维修入口响应
class AirSendMaintenanceEntryResponse
{
public:
AirSendMaintenanceEntryResponse()
{
this->Success = false;
this->Errors = list<string>();
this->MaintenanceId = {};
}
string MaintenanceId;// { get; set; }
bool Success;// { get; set; }
list<string> Errors;// { get; set; }
};
//--------------------namespace BMW.ISPI.IstaServices.Contract.AIR.Data------------------//
//航空动态牵引力控制系统
class AirDtc
{
public:
bool IsCombined;//{ get; set; }
bool IsVirtual;// { get; set; }
bool IsRelevant;// { get; set; }
long double Id;// { get; set; }
long No;// { get; set; }
};
//航空经销商数据
class AirDealerData
{
public:
string DealerAddress;// { get; set; }
string DealerCity;// { get; set; }
string DealerCountry;// { get; set; }
string DealerPostCode;// { get; set; }
string DealerEMail;// { get; set; }
string DealerName;// { get; set; }
string DealerPhone;// { get; set; }
string DistributionPartnerNumber; // 分销商数量{ get; set; }
string OutletNumber;// { get; set; }
string OutletNumber;// { get; set; }
};
//航空服务历史LP2响应
class AirServiceHistoryLP2Response
{
public:
int Fehlergrund;// { get; set; }
bool Status;// { get; set; }
vector<string>SgbdName;// { get; set; }
vector<byte> WartungsTag;// { get; set; }
vector< byte>WartungsMonat;// { get; set; }
vector<unsigned int> WartungsJahr;// { get; set; }
vector<byte> KorrekturZaehler;// { get; set; }
vector<unsigned long> KmStand;// { get; set; }
vector<byte> FlagBmwHaendler;// { get; set; }
vector<string> HaendlerNummer;// { get; set; }
vector<byte> WartungsStatus;// { get; set; }
vector<byte> AnzahlWartungsEintraege;// { get; set; }
map<string, byte> WartungsText;// { get; set; }
map<string, byte> StatusWartungsPos;// { get; set; }
map<string, long> RestDistanz;// { get; set; }
map<string, unsigned int> RestZeit;// { get; set; }
int ServiceEntrySize;
};
//航空汽车数据
class AirVehicleData
{
public:
long double Gwsz;// { get; set; }
string VIN7;// { get; set; }
string VIN10Prefix;// { get; set; }
};
//航空发送维修入口
class AirSendMaintenanceEntry
{
public:
AirDealerData DealerData;// { get; set; }
AirVehicleData VehicleData;// { get; set; }
string IstaCaseId;// { get; set; }
};
//航空开始属性
class AirStartProperties
{
// Token: 0x06000B3D RID: 2877 RVA: 0x000077F4 File Offset: 0x000059F4
public:
AirStartProperties()
{
this->PreRepTaskIds = list<string>();
}
string PreRepId;// { get; set; }
list<string> PreRepTaskIds;// { get; }
string Language;// { get; set; }
string Vin;// { get; set; }
bool VehicleDiagnostic;// { get; set; }
list<AirDtc> Faultcodes;// { get; set; }
list<bool> RelevanceToFaultcodes;// { get; set; }
list<AirPerceivedSymptom> PerceivedSymptoms;// { get; set; }
set<string> DiagnosticCodes;// { get; set; }
string NavigationTarget;//{ get; set; }
};
//航空感知症状
class AirPerceivedSymptom
{
public:
string VfcType;// { get; set; }
string VfcNr;// { get; set; }
string ParentNodeIdentifier;// { get; set; }
};
//航空开始反应
class AirStartResponse
{
public:
int Fehlergrund;// { get; set; }
};
#endif // !_ISTA_AIR_SERVICE_CLIENT_H