本文整理汇总了C#中WebChannelFactory.Open方法的典型用法代码示例。如果您正苦于以下问题:C# WebChannelFactory.Open方法的具体用法?C# WebChannelFactory.Open怎么用?C# WebChannelFactory.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebChannelFactory
的用法示例。
在下文中一共展示了WebChannelFactory.Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddTodos
/// <summary>
/// Perform a ITodoApi AddTodos request.
/// </summary>
private void AddTodos(string name, DateTime expirationDate)
{
using (var client = new WebChannelFactory<ITodoApi>(new WebHttpBinding(), new Uri(_hostAddress)))
{
client.Open();
var channel = client.CreateChannel();
using (new OperationContextScope((IContextChannel)channel))
{
channel.CreateTodo(new TodoType() { Name = name, ExpirationDate = expirationDate });
}
}
}
示例2: CreateComplexObject
public void CreateComplexObject()
{
using (var client = new WebChannelFactory<IDataTest>(new WebHttpBinding(), new Uri(_hostAddress)))
{
client.Open();
var channel = client.CreateChannel();
using (new OperationContextScope((IContextChannel)channel))
{
channel.CreateComplexObject(GetComplexObject());
ValidateHttpStatusResponse(HttpStatusCode.OK);
}
}
}
示例3: GetTodos
public void GetTodos()
{
using (var client = new WebChannelFactory<ITodoApi>(new WebHttpBinding(), new Uri(_hostAddress)))
{
client.Open();
var channel = client.CreateChannel();
using (new OperationContextScope((IContextChannel)channel))
{
var todos = channel.GetTodos();
ValidateHttpStatusResponse(HttpStatusCode.OK);
Assert.AreEqual(3, todos.Todo.Length);
}
}
}
示例4: CreateInts
public void CreateInts()
{
using (var server = new WebServiceHost(new DataService(), new Uri(_hostAddress)))
using (var client = new WebChannelFactory<IDataTest>(new WebHttpBinding(), new Uri(_hostAddress)))
{
server.Open();
client.Open();
var channel = client.CreateChannel();
using (new OperationContextScope((IContextChannel)channel))
{
channel.CreateInts( new []{24,42});
ValidateHttpStatusResponse(HttpStatusCode.OK);
}
}
}
示例5: GetVersion
public void GetVersion()
{
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 version = channel.GetVersion();
ValidateHttpStatusResponse(HttpStatusCode.OK);
Assert.AreEqual(VersionType.v1_0, version);
}
}
}
示例6: GetTodo
public void GetTodo()
{
using (var client = new WebChannelFactory<ITodoApi>(new WebHttpBinding(), new Uri(_hostAddress)))
{
client.Open();
var channel = client.CreateChannel();
using (new OperationContextScope((IContextChannel)channel))
{
var todo = channel.GetTodo("1");
ValidateHttpStatusResponse(HttpStatusCode.OK);
Assert.AreEqual(true, todo.idSpecified);
Assert.AreEqual(1, todo.id);
Assert.AreEqual(false, todo.IsDone);
}
}
}
示例7: SetupTest
public void SetupTest()
{
_hostAddress = string.Format("http://{0}:9222/RestService/TodoService", ipAddress);
using (var client = new WebChannelFactory<ITodoApi>(new WebHttpBinding(), new Uri(_hostAddress)))
{
client.Open();
var channel = client.CreateChannel();
using (new OperationContextScope((IContextChannel)channel))
{
//GetVersion will reset the state of the server to it's initial state as well.
var version = channel.GetVersion();
ValidateHttpStatusResponse(HttpStatusCode.OK);
Assert.AreEqual(VersionType.v1_0, version);
}
}
}
示例8: GetTodos
/// <summary>
/// Perform a ITodoApi GetTodos request.
/// </summary>
private TodosType GetTodos()
{
using (var client = new WebChannelFactory<ITodoApi>(new WebHttpBinding(), new Uri(_hostAddress)))
{
client.Open();
var channel = client.CreateChannel();
using (new OperationContextScope((IContextChannel)channel))
{
return channel.GetTodos();
}
}
}
示例9: 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);
}
}
}
示例10: UpdateTodo
public void UpdateTodo()
{
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();
var todo = new TodoType();
using (new OperationContextScope((IContextChannel)channel))
{
try
{
todo = channel.GetTodo("1");
}
catch (CommunicationException ex)
{
ValidateHttpStatusResponse(ex, HttpStatusCode.BadRequest);
}
}
todo.IsDone = true;
using (new OperationContextScope((IContextChannel) channel))
{
channel.UpdateTodo(todo.id.ToString(), todo);
ValidateHttpStatusResponse(HttpStatusCode.OK);
}
}
}
示例11: CreateTodo
public void CreateTodo()
{
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();
var todo = new TodoType { id = 6, idSpecified = true, IsDone = false, Name = "New Item", Description = "This items should be fixed!", ExpirationDate = DateTime.Now.AddDays(2) };
using (new OperationContextScope((IContextChannel)channel))
{
try
{
var newId = channel.CreateTodo(todo);
}
catch (CommunicationException ex)
{
ValidateHttpStatusResponse(ex, HttpStatusCode.BadRequest);
}
}
todo.idSpecified = false;
using (new OperationContextScope((IContextChannel)channel))
{
var newId = channel.CreateTodo(todo);
ValidateHttpStatusResponse(HttpStatusCode.OK);
Assert.AreEqual(4, newId);
}
}
}
示例12: UpdateComplexObjects
public void UpdateComplexObjects()
{
using (var client = new WebChannelFactory<IDataTest>(new WebHttpBinding(), new Uri(_hostAddress)))
{
client.Open();
var channel = client.CreateChannel();
using (new OperationContextScope((IContextChannel)channel))
{
var input = GetComplexObjects();
var result = channel.UpdateComplexObjects(input);
ValidateHttpStatusResponse(HttpStatusCode.OK);
MyAssert.AreEqual(input, result);
}
}
}
示例13: UpdateUShorts
public void UpdateUShorts()
{
using (var client = new WebChannelFactory<IDataTest>(new WebHttpBinding(), new Uri(_hostAddress)))
{
client.Open();
var channel = client.CreateChannel();
using (new OperationContextScope((IContextChannel)channel))
{
var input = new[] { (ushort)42, (ushort)24, (ushort)33 };
var result = channel.UpdateUShorts(input);
ValidateHttpStatusResponse(HttpStatusCode.OK);
Assert.AreEqual(input.Length, result.Length);
Assert.AreEqual(input, result);
}
}
}
示例14: UpdateTimeSpans
public void UpdateTimeSpans()
{
using (var client = new WebChannelFactory<IDataTest>(new WebHttpBinding(), new Uri(_hostAddress)))
{
client.Open();
var channel = client.CreateChannel();
using (new OperationContextScope((IContextChannel)channel))
{
var input = new[] { new TimeSpan(1,2,3,4,5), new TimeSpan(4,4,5,6), new TimeSpan(3,3,3,3) };
var result = channel.UpdateTimeSpans(input);
ValidateHttpStatusResponse(HttpStatusCode.OK);
Assert.AreEqual(input.Length, result.Length);
Assert.AreEqual(input, result);
}
}
}
示例15: UpdateDateTimes
public void UpdateDateTimes()
{
using (var client = new WebChannelFactory<IDataTest>(new WebHttpBinding(), new Uri(_hostAddress)))
{
client.Open();
var channel = client.CreateChannel();
using (new OperationContextScope((IContextChannel)channel))
{
var input = new [] {DateTime.Now, DateTime.Now.AddDays(4).AddHours(2)};
var result = channel.UpdateDateTimes(input);
ValidateHttpStatusResponse(HttpStatusCode.OK);
Assert.AreEqual(input.Length, result.Length);
Assert.AreEqual(input, result);
}
}
}