//SSL:

//1 AccountLogin.aspx.cs 获取页面content
 前端引用#region 前端引用
CustomerLogonContent content = null;
content = CustomerFacade.GetCustomerLogonContent(logonRequest, CustomerEntityCreator.Current.GetCustomerSubscriptionInfo());

//2 CustomerFacade.cs
public static CustomerLogonContent GetCustomerLogonContent
(CustomerLogonService logonService, CustomerSubscriptionInfo subscriptionInfo)
  {
return MessageProcessor.Initiate<CustomerLogonContent>("CustomerLogon_CustomerLogon", logonService, subscriptionInfo);
}
#endregion


//CommonLibrary MessageProcessor.cs
//三步:构造消息,处理消息(调用WebService),返回消息
 构造消息对象,处理序列化的消息,返回结果#region 构造消息对象,处理序列化的消息,返回结果
public static T Initiate<T>(string msgName, params object[] bizContent) where T : class
  {
return Initiate<T>(0, msgName, bizContent);
}

public static T Initiate<T>(int timeout, string msgName, params object[] bizContent) where T : class
  {
// construct message
RequestMessage requestMsg = ConstructRequestMessage(msgName, bizContent);

// invoke webservice
string response = InvokeDelegateWebMethod(SerializeMessage<RequestMessage>(requestMsg), timeout);

if (string.IsNullOrEmpty(response))
 {
throw new Exception("MPE WebService response a null or empty value.");
}

// deserialize response msg
ResponseMessage responseMsg = DeserializeMessage<ResponseMessage>(response);

return responseMsg.BizContent as T;
}
#endregion

 构造消息对象,消息体有三部分Name,ServerInfo,ProcessStep,参数信息#region 构造消息对象,消息体有三部分Name,ServerInfo,ProcessStep,参数信息

private static RequestMessage ConstructRequestMessage(string msgName, params object[] bizContent)
 {
RequestMessage msg = new RequestMessage();
msg.Name = msgName;
msg.ServerInfo = new Newegg.MPE.Common.ServerInfo();
msg.ServerInfo.JumpedDBAlias = MPERequestContext.JumpedDBAlias;
msg.ServerInfo.QueryDBName = ConfigurationManager.ServerConfiguration.ServerInfo.QueryDBAlias;
msg.ServerInfo.HisQueryDBAlias = ConfigurationManager.ServerConfiguration.ServerInfo.HisQueryDBAlias;
msg.ServerInfo.ServerID = ConfigurationManager.ServerConfiguration.ServerInfo.ServerId;
msg.ServerInfo.IsCARequest = string.Compare(StringResource.ThreadStorage_Value_RequestHost_CA,
LogicalThreadContext.GetData(StringResource.ThreadStorage_Key_RequestHost) as string) == 0;
msg.ServerInfo.IsUSRequest = string.Compare(StringResource.ThreadStorage_Value_RequestHost_Default,
LogicalThreadContext.GetData(StringResource.ThreadStorage_Key_RequestHost) as string) == 0;
msg.ServerInfo.CurrencyExchangeRate = (decimal)LogicalThreadContext.GetData(StringResource.ThreadStorage_Key_CurrencyExchangeRate);
msg.ServerInfo.RequestHost = LogicalThreadContext.GetData(StringResource.ThreadStorage_Key_RequestHost) as string;
msg.ServerInfo.IsMobileDevice = (bool)LogicalThreadContext.GetData(StringResource.ThreadStorage_Key_Is_Mobile_Device);
msg.ProcessStep = MessageProcessStep.Init;
if (bizContent != null)
 {
foreach (object o in bizContent)
 {
msg.AddBizObject(o);
}
}
return msg;
}

#endregion

 处理序列化的消息对象#region 处理序列化的消息对象
private static string InvokeDelegateWebMethod(string requestMsg, int timeout)
 {
return WebServiceCommand.Invoke<DelegateWebService>(timeout, DelegateWebService.Method_Process, requestMsg) as string;
}


// 在WebServiceCommand.cs中,期间省略了异常处理代码
public static object Invoke<T>(int timeout, string methodName, params object[] parameters) where T : SoapHttpClientProtocol
 {
WebServiceItem webServiceItem = WebServiceManager.GetWebServiceItem(typeof(T));
MethodInfo methodInfo = webServiceItem.MethodHashTable[methodName];
ServiceItem serviceItem = ConfigurationManager.WebServiceConfiguration.GetServiceItem(webServiceItem.Alias);
HostInfo hostInfo = ConfigurationManager.ServerConfiguration.HostSettings.HostInfoCollection[serviceItem.GroupName];

SoapHttpClientProtocol webServiceInstance = webServiceItem.CreatInstance();
if (hostInfo.UseProxy)
 {
webServiceInstance.Proxy = GetWebProxy(ConfigurationManager.ServerConfiguration.HostProxy);
}
if (timeout <= 0)
 {
webServiceInstance.Timeout = serviceItem.Timeout;
}
else
 {
webServiceInstance.Timeout = timeout;
}

if (hostInfo.InvokeOrderType == InvokeOrderType.Sequence)
 {
foreach (string host in hostInfo.Hosts)
 {
webServiceInstance.Url = host + serviceItem.Path;
try
 {
return methodInfo.Invoke(webServiceInstance, parameters);
}
catch (Exception e)
 {
WebServiceLogger.WriteCallWebServiceFaildLog(webServiceItem.Alias, webServiceInstance.Timeout, webServiceInstance.Url, e);
invokeException = e;
}
}
}
else
 {
List<string> hosts = new List<string>(hostInfo.Hosts);
if (hostInfo.InvokeOrderType == InvokeOrderType.RandomOthers)
 {
webServiceInstance.Url = hosts[0] + serviceItem.Path;
try
 {
return methodInfo.Invoke(webServiceInstance, parameters);
}
catch (Exception e)
 {
WebServiceLogger.WriteCallWebServiceFaildLog(webServiceItem.Alias, webServiceInstance.Timeout, webServiceInstance.Url, e);
invokeException = e;
}
}
Random hostRandom = new Random();
int hostIndex;
while (hosts.Count > 0)
 {
hostIndex = hostRandom.Next(hosts.Count);
webServiceInstance.Url = hosts[hostIndex] + serviceItem.Path;
try
 {
return methodInfo.Invoke(webServiceInstance, parameters);
}
catch (Exception e)
 {
WebServiceLogger.WriteCallWebServiceFaildLog(webServiceItem.Alias, webServiceInstance.Timeout, webServiceInstance.Url, e);
invokeException = e;
}
hosts.RemoveAt(hostIndex);
}
}
//WebServiceLogger.ExecuteWebServiceException(webServiceItem.Alias, webServiceInstance.Timeout, webServiceInstance.Url);
throw new Exception("invoke webservcie error,", invokeException);
}
#endregion
发表于
2008-11-19 13:58
ezmo
阅读( 487)
评论()
收藏
举报
|
|