本文整理汇总了C#中WebChannelFactory类的典型用法代码示例。如果您正苦于以下问题:C# WebChannelFactory类的具体用法?C# WebChannelFactory怎么用?C# WebChannelFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebChannelFactory类属于命名空间,在下文中一共展示了WebChannelFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Console.ReadLine();
//var client = new EvalServiceClient("BasicHttpBinding_IEvalService");
WebChannelFactory<IEvalService> cf =
new WebChannelFactory<IEvalService>(new Uri("http://localhost:8080/evalservice"));
IEvalService client = cf.CreateChannel();
client.SubmitEval(new Eval
{
Comments = "This came from code",
Submitter = "Sean",
TimeSubmitted = DateTime.Now
});
Console.WriteLine("Save success");
Console.WriteLine("Load Evals");
var evals = client.GetEvals();
foreach (var eval in evals)
{
Console.WriteLine(eval.Comments);
}
Console.WriteLine("End load Evals");
Console.Read();
}
示例2: GetToken
public GetTokenResponse GetToken(string sessionId, string tokenId)
{
using (new ApplicationContextScope(new ApplicationContext()))
{
ApplicationContext.Current.Items["SessionId"] = sessionId;
try
{
var channelFactory =
new WebChannelFactory<ITokenServiceRest>(Configuration.TokenServiceConfigurationName);
ITokenServiceRest channel = channelFactory.CreateChannel();
if (channel is IContextChannel)
using (new OperationContextScope(channel as IContextChannel))
{
WebOperationContext.Current.OutgoingRequest.Headers.Add("X-MethodName", "GenerateToken");
GetTokenResponse response = channel.GetToken(tokenId);
return response;
}
}
catch (Exception exception)
{
Logger.LogException(exception, Source, "GenerateToken", Severity.Major);
}
}
return null;
}
示例3: GetVoucherAmount
public decimal GetVoucherAmount(string sessionId, string voucherCode)
{
using (new ApplicationContextScope(new ApplicationContext()))
{
ApplicationContext.Current.Items["SessionId"] = sessionId;
try
{
var channelFactory =
new WebChannelFactory<IPaymentServiceRest>(Configuration.PaymentServiceConfigurationName);
IPaymentServiceRest channel = channelFactory.CreateChannel();
if (channel is IContextChannel)
using (new OperationContextScope(channel as IContextChannel))
{
WebOperationContext.Current.OutgoingRequest.Headers.Add("X-MethodName", "GetVoucherAmount");
var response = channel.GetVoucherAmount(sessionId, voucherCode);
return response;
}
}
catch(Exception ex)
{
Logger.LogException(ex, Source, "GetVoucherAmount", Severity.Critical);
}
}
return 0M;
}
示例4: GetTodosFiltered
public void GetTodosFiltered()
{
using (var server = new WebServiceHost(new TodoService(), new Uri(_hostAddress)))
using (var client = new WebChannelFactory<ITodoApi>(new WebHttpBinding(), new Uri(_hostAddress)))
{
server.Open();
client.Open();
var channel = client.CreateChannel();
using (new OperationContextScope((IContextChannel)channel))
{
var todos = channel.GetTodosFiltered(true);
ValidateHttpStatusResponse(HttpStatusCode.OK);
Assert.AreEqual(1, todos.Todo.Length);
}
using (new OperationContextScope((IContextChannel)channel))
{
var todos = channel.GetTodosFiltered(false);
ValidateHttpStatusResponse(HttpStatusCode.OK);
Assert.AreEqual(2, todos.Todo.Length);
}
}
}
示例5: Main
/// <summary>
/// </summary>
public static void Main(string[] args)
{
try
{
Console.WriteLine("Gathering files");
var files = new List<FileDescriptor>();
if (args != null)
{
files.AddRange(
args
.Where(File.Exists)
.Select(a => new FileDescriptor { Name = a, Contents = File.ReadAllBytes(a) }));
}
Console.WriteLine("Send files");
using (var f = new WebChannelFactory<IFileTracker>(new Uri("http://localhost/samplewcf/Call.svc/FileTracker")))
{
var c = f.CreateChannel();
var i = c.Track(files.ToArray());
Console.WriteLine("Server said:");
Console.Write(i);
}
Console.WriteLine("Done");
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
Console.ResetColor();
}
}
示例6: CreateWorldGeocoder
/// <summary>
/// Creates a new instance of the <see cref="WorldGeocoder"/> class for the specified
/// service configuration.
/// </summary>
/// <param name="serviceInfo">The instance of the geocoding service configuration
/// specifying World geocoder service to create geocoder for.</param>
/// <param name="exceptionHandler">Exception handler.</param>
/// <returns>A new instance of the <see cref="WorldGeocoder"/> class.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="serviceInfo"/> is a null
/// reference.</exception>
public static GeocoderBase CreateWorldGeocoder(GeocodingServiceInfo serviceInfo,
IServiceExceptionHandler exceptionHandler)
{
CodeContract.RequiresNotNull("serviceInfo", serviceInfo);
// Create binding for the geocoder REST service.
var webBinding = ServiceHelper.CreateWebHttpBinding("WorldGeocoder");
var binding = new CustomBinding(webBinding);
var messageEncodingElement = binding.Elements.Find<WebMessageEncodingBindingElement>();
messageEncodingElement.ContentTypeMapper = new ArcGisWebContentTypeMapper();
// Create endpoint for the geocoder REST service.
var contract = ContractDescription.GetContract(typeof(IGeocodingService));
var serviceAddress = new EndpointAddress(serviceInfo.RestUrl);
var endpoint = new WebHttpEndpoint(contract, serviceAddress);
endpoint.Binding = binding;
// Replace default endpoint behavior with a customized one.
endpoint.Behaviors.Remove<WebHttpBehavior>();
endpoint.Behaviors.Add(new GeocodingServiceWebHttpBehavior());
// Create the geocoder instance.
var channelFactory = new WebChannelFactory<IGeocodingService>(endpoint);
var client = new GeocodingServiceClient(channelFactory, serviceInfo, exceptionHandler);
return new WorldGeocoder(serviceInfo, client);
}
示例7: CreateServiceManagementChannel
public static IGithubServiceManagement CreateServiceManagementChannel(Uri remoteUri, string username, string password)
{
WebChannelFactory<IGithubServiceManagement> factory;
if (_factories.ContainsKey(remoteUri.ToString()))
{
factory = _factories[remoteUri.ToString()];
}
else
{
factory = new WebChannelFactory<IGithubServiceManagement>(remoteUri);
factory.Endpoint.Behaviors.Add(new GithubAutHeaderInserter() {Username = username, Password = password});
WebHttpBinding wb = factory.Endpoint.Binding as WebHttpBinding;
wb.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
wb.Security.Mode = WebHttpSecurityMode.Transport;
wb.MaxReceivedMessageSize = 10000000;
if (!string.IsNullOrEmpty(username))
{
factory.Credentials.UserName.UserName = username;
}
if (!string.IsNullOrEmpty(password))
{
factory.Credentials.UserName.Password = password;
}
_factories[remoteUri.ToString()] = factory;
}
return factory.CreateChannel();
}
示例8: Main
static void Main(string[] args)
{
Console.WriteLine("Pressione <ENTER> para executar o ws.client...");
Console.ReadLine();
// http://localhost:2893/ (URI)
WebChannelFactory<IProposta> client =
new WebChannelFactory<IProposta>(
new Uri("http://localhost:2893/Proposta.svc"));
IProposta clientProposta = client.CreateChannel();
Proposta proposta = new Proposta()
{
DescricaoProposta = "Essa proposta foi inserida a partir do console.",
NomeCliente = "João",
DataHoraEnviada = DateTime.Now
};
Proposta proposta1 = new Proposta()
{
DescricaoProposta = "Essa proposta foi inserida a partir do console.",
NomeCliente = "Maria",
DataHoraEnviada = DateTime.Now
};
clientProposta.EnviarProposta(proposta);
clientProposta.EnviarProposta(proposta1);
Console.WriteLine("Chamada Finalizada...");
Console.ReadLine();
}
示例9: ChangeMobile
public ChangeMobileResponse ChangeMobile(string sessionId, string authenticationId, string mobile)
{
using (new ApplicationContextScope(new ApplicationContext()))
{
ApplicationContext.SetSessionId(sessionId);
try
{
var channelFactory =
new WebChannelFactory<ILoginServiceRest>(Configuration.LoginServiceConfigurationName);
ILoginServiceRest channel = channelFactory.CreateChannel();
if (channel is IContextChannel)
using (new OperationContextScope(channel as IContextChannel))
{
WebOperationContext.Current.OutgoingRequest.Headers.Add("X-MethodName", "ChangeMobile");
return channel.ChangeMobile(sessionId, authenticationId, mobile);
}
}
catch (Exception exception)
{
Logger.LogException(exception, Source, "ChangeMobile", Severity.Major);
}
}
return null;
}
示例10: CreateGatewayManagementChannel
public static IGatewayServiceManagement CreateGatewayManagementChannel(Binding binding, Uri remoteUri, X509Certificate2 cert)
{
WebChannelFactory<IGatewayServiceManagement> factory = new WebChannelFactory<IGatewayServiceManagement>(binding, remoteUri);
factory.Endpoint.Behaviors.Add(new ServiceManagementClientOutputMessageInspector());
factory.Credentials.ClientCertificate.Certificate = cert;
return factory.CreateChannel();
}
示例11: GetReservationListing
public ReservationListingResponse GetReservationListing(string sessionId, RequestParams requestParams)
{
using (new ApplicationContextScope(new ApplicationContext()))
{
ApplicationContext.SetSessionId(sessionId);
try
{
var channelFactory =
new WebChannelFactory<IAirlinesAdminServiceRest>(
Configuration.AirlinesAdminServiceConfigurationName);
IAirlinesAdminServiceRest channel = channelFactory.CreateChannel();
if (channel is IContextChannel)
using (new OperationContextScope(channel as IContextChannel))
{
WebOperationContext.Current.OutgoingRequest.Headers.Add("X-MethodName",
"GetReservationListing");
ReservationListingResponse response = channel.GetReservationListing(sessionId, requestParams);
if (response != null && response.IsSuccess)
{
return response;
}
}
}
catch (Exception exception)
{
Logger.LogException(exception, Source, "GetReservationListing", Severity.Major);
}
}
return new ReservationListingResponse
{
IsSuccess = false,
ErrorMessage = "Failed to get Reservation Listing. Please try again after some time"
};
}
示例12: CreateSession
public string CreateSession(string sessionId)
{
using (new ApplicationContextScope(new ApplicationContext()))
{
ApplicationContext.Current.Items["SessionId"] = sessionId;
try
{
var channelFactory =
new WebChannelFactory<ISessionServiceRest>(Configuration.SessionServiceConfigurationName);
ISessionServiceRest channel = channelFactory.CreateChannel();
if (channel is IContextChannel)
using (new OperationContextScope(channel as IContextChannel))
{
WebOperationContext.Current.OutgoingRequest.Headers.Add("X-MethodName", "CreateSession");
return channel.CreateSession(sessionId);
}
}
catch (Exception exception)
{
Logger.LogException(exception, Source, "AddRequestSessionData", Severity.Major);
}
}
return null;
}
示例13: Main
static void Main(string[] args)
{
var factory=new WebChannelFactory<IMachine>(new Uri("http://localhost:8080/wcf"));
IMachine machine = factory.CreateChannel();
while (true)
{
Console.WriteLine("To submit press 1 \nTo get all machines press 2 \nTo get specific machine name press 3 ");
string readLine = Console.ReadLine();
if (readLine == "1")
{
Console.WriteLine("please enter machine name :\n");
string machineName = Console.ReadLine();
machine.submitMachine(machineName);
}
else if (readLine == "2")
{
string allMachines = machine.getAllMachines();
Console.WriteLine(allMachines);
}
else if (readLine == "3")
{
Console.WriteLine("please enter the machine Id \n");
string machineId = Console.ReadLine();
string machineName = machine.getMachineName(machineId);
Console.WriteLine(machineName);
}
else
{
break;
}
}
}
示例14: CreateSqlDatabaseManagementChannel
public static ISqlDatabaseManagement CreateSqlDatabaseManagementChannel(Binding binding, Uri remoteUri, X509Certificate2 cert, string requestSessionId)
{
WebChannelFactory<ISqlDatabaseManagement> factory = new WebChannelFactory<ISqlDatabaseManagement>(binding, remoteUri);
factory.Endpoint.Behaviors.Add(new ClientOutputMessageInspector(requestSessionId));
factory.Credentials.ClientCertificate.Certificate = cert;
return factory.CreateChannel();
}
示例15: Blip
public Blip(string user, string password)
{
this.user = user;
this.password = password;
channelFactory = new WebChannelFactory<IBlipApi>(GetBinding(), new Uri(BlipApiUrl));
api = channelFactory.CreateChannel();
}