silverlight 동적 생성 WCF 서비스
3627 단어 silverlight
/// <summary>
///
/// </summary>
public static class CreateService
{
#region//
/// <summary>
///
/// </summary>
/// <typeparam name="serviceType"> </typeparam>
/// <returns></returns>
public static T GetBasicService<T>(string serviceType) where T : class
{
T instance = null;
BasicHttpBinding bhb = new BasicHttpBinding();
string address = GetServerUrl(serviceType);
EndpointAddress endPointAddress = new EndpointAddress(address);
object[] paras = new object[2];
paras[0] = bhb;
paras[1] = endPointAddress;
ConstructorInfo constructor = null;
try
{
Type[] types = new Type[2];
types[0] = typeof(System.ServiceModel.Channels.Binding);
types[1] = typeof(System.ServiceModel.EndpointAddress);
constructor = typeof(T).GetConstructor(types);
}
catch (Exception)
{
}
if (constructor != null)
instance = (T)constructor.Invoke(paras);
return instance;
}
/// <summary>
///
/// </summary>
/// <param name="serviceType"> </param>
/// <returns></returns>
public static T GetCustomerService<T>(string serviceType) where T : class
{
T _instance = null;
string serviceUri = GetServerUrl(serviceType);
if (string.IsNullOrEmpty(serviceUri)) return null;
object[] paras = new object[2];
var elements = new List<BindingElement>();
elements.Add(new TextMessageEncodingBindingElement() { MessageVersion = MessageVersion.Default, WriteEncoding = Encoding.UTF8 });
HttpTransportBindingElement bindingElement = new HttpTransportBindingElement();
bindingElement.MaxReceivedMessageSize = int.MaxValue;
bindingElement.MaxBufferSize = int.MaxValue;
elements.Add(bindingElement);
CustomBinding binding = new CustomBinding(elements);
EndpointAddress address = new EndpointAddress(new Uri(serviceUri, UriKind.Absolute));
paras[0] = binding;
paras[1] = address;
ConstructorInfo constructor = null;
try
{
Type[] types = new Type[2];
types[0] = typeof(System.ServiceModel.Channels.Binding);
types[1] = typeof(System.ServiceModel.EndpointAddress);
constructor = typeof(T).GetConstructor(types);
}
catch (Exception)
{
return null;
}
if (constructor != null)
_instance = (T)constructor.Invoke(paras);
return _instance;
}
#endregion
#region//
/// <summary>
/// URL
/// </summary>
/// <returns></returns>
private static string GetServerUrl(string serviceName)
{
return App.ServiceUriList[serviceName];
}
#endregion
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Silverlight animation performanceAnimation performance can be improved with several configurations: Desired Frame Rate Configure in the WEB project: Hard...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.