本文整理汇总了C#中CalculatorClient类的典型用法代码示例。如果您正苦于以下问题:C# CalculatorClient类的具体用法?C# CalculatorClient怎么用?C# CalculatorClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CalculatorClient类属于命名空间,在下文中一共展示了CalculatorClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
ServiceReference1.CalculatorClient client = new CalculatorClient();
double value1 = 100.00D;
double value2 = 15.99D;
double result = client.Add(value1, value2);
Console.WriteLine("Add({0},{1}) = {2}", value1,value2, result);
value1 = 145.00D;
value2 = 76.54D;
result = client.Substract(value1, value2);
Console.WriteLine("Substract({0},{1}) = {2}",value1,value2,result);
value1 = 9.00D;
value2 = 81.25D;
result = client.Multiply(value1, value2);
Console.WriteLine("Mutiply({0},{1}) = {2}", value1, value2, result);
value1 = 22.00D;
value2 = 7.00D;
result = client.Divide(value1, value2);
Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
client.Close();
Console.ReadLine();
}
示例2: Main
static void Main(string[] args)
{
// Create a proxy with default client endpoint configuration.
CalculatorClient client = new CalculatorClient();
// Add
double value1 = 100.00D;
double value2 = 15.99D;
double result = client.Add(value1, value2);
Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
// Subtract
value1 = 145.00D;
value2 = 76.54D;
result = client.Subtract(value1, value2);
Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);
// Multiply
value1 = 9.00D;
value2 = 81.25D;
result = client.Multiply(value1, value2);
Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);
// Divide
value1 = 22.00D;
value2 = 7.00D;
result = client.Divide(value1, value2);
Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
//Closing the client gracefully closes the connection and cleans up resources
client.Close();
Console.WriteLine();
Console.WriteLine("Press <ENTER> to terminate client.");
Console.ReadLine();
}
示例3: Main
static void Main(string[] args)
{
CalculatorClient proxy = new CalculatorClient();
Console.WriteLine("Client is running at " + DateTime.Now.ToString());
Console.WriteLine("Sum of two numbers... 5+5 =" + proxy.Add(5, 5));
Console.ReadLine();
}
示例4: Main
static void Main(string[] args)
{
//create an instance of wcf proxy
CalculatorClient client = new CalculatorClient();
//call the service operations
double value1 = 100.00d;
double value2 = 15.99d;
double result= client.Add(value1,value2);
Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
// Call the Subtract service operation.
value1 = 145.00D;
value2 = 76.54D;
result = client.Subtract(value1, value2);
Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);
// Call the Multiply service operation.
value1 = 9.00D;
value2 = 81.25D;
result = client.Multiply(value1, value2);
Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);
// Call the Divide service operation.
value1 = 22.00D;
value2 = 7.00D;
result = client.Divide(value1, value2);
Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
//Step 3: Closing the client gracefully closes the connection and cleans up resources.
client.Close();
}
示例5: Main
static void Main()
{
// Create a client with given client endpoint configuration
CalculatorClient client = new CalculatorClient();
try
{
double value1;
double value2;
double result;
// Call the Multiply service operation with arguments between 1 and 10
value1 = 2.00D;
value2 = 5.25D;
result = client.Multiply(value1, value2);
Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);
// Call the Multiply service operation with arguments outside 1 and 10
value1 = 9.00D;
value2 = 81.25D;
result = client.Multiply(value1, value2);
Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);
}
catch (FaultException e)
{
Console.WriteLine("{0}: {1}", e.GetType(), e.Message);
}
//Closing the client gracefully closes the connection and cleans up resources
client.Close();
Console.WriteLine();
Console.WriteLine("Press <ENTER> to terminate client.");
Console.ReadLine();
}
示例6: Main
static void Main(string[] args)
{
var client = new CalculatorClient();
double value1 = 100.00D;
double value2 = 15.99D;
double result = client.Add(value1, value2);
Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
// Call the Subtract service operation.
value1 = 145.00D;
value2 = 76.54D;
result = client.Subtract(value1, value2);
Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);
// Call the Multiply service operation.
value1 = 9.00D;
value2 = 81.25D;
result = client.Multiply(value1, value2);
Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);
// Call the Divide service operation.
value1 = 22.00D;
value2 = 7.00D;
result = client.Divide(value1, value2);
Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
client.Close();
Console.WriteLine();
Console.WriteLine("Press <ENTER> to terminate client.");
Console.ReadLine();
}
示例7: Main
static void Main(string[] args)
{
CalculatorClient client = new CalculatorClient();
int num1 = 100;
int num2 = 15;
Console.WriteLine("Addition {0}, {1} = {2}", num1, num2, client.Addition(num1, num2));
}
示例8: DemonstrateProblemUsingCanThrow
// This method shows one problem with the "using" statement.
//
// The service Aborts the channel to indicate that the session failed. When that
// happens, the client gets an Exception from Close. Because Dispose is the same as
// Close, the client gets an Exception from Dispose as well. The close of the "using"
// block results in a call to client.Dispose. Typically developers use "using" to avoid
// having to write try/catch/finally code. However, because the closing brace can throw,
// the try/catch is necessary.
static void DemonstrateProblemUsingCanThrow()
{
Console.WriteLine("=");
Console.WriteLine("= Demonstrating problem: closing brace of using statement can throw.");
Console.WriteLine("=");
try
{
// Create a new client.
using (CalculatorClient client = new CalculatorClient())
{
// Call Divide and catch the associated Exception. This throws because the
// server aborts the channel before returning a reply.
try
{
client.Divide(0.0, 0.0);
}
catch (CommunicationException e)
{
Console.WriteLine("Got {0} from Divide.", e.GetType());
}
}
// The previous line calls Dispose on the client. Dispose and Close are the
// same thing, and the Close is not successful because the server Aborted the
// channel. This means that the code after the using statement does not run.
Console.WriteLine("Hope this code wasn't important, because it might not happen.");
}
catch (CommunicationException e)
{
// The closing brace of the "using" block throws, so we end up here. If you
// want to use using, you must surround it with a try/catch
Console.WriteLine("Got {0}", e.GetType());
}
}
示例9: Main
static void Main()
{
// Create a proxy with given client endpoint configuration
CalculatorClient client = new CalculatorClient();
// Call the Add service operation.
double value1 = 100.00D;
double value2 = 15.99D;
double result = client.Add(value1, value2);
Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
// Call the Subtract service operation.
value1 = 145.00D;
value2 = 76.54D;
result = client.Subtract(value1, value2);
Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);
// Call the Multiply service operation.
value1 = 9.00D;
value2 = 81.25D;
result = client.Multiply(value1, value2);
Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);
// Call the Divide service operation.
value1 = 22.00D;
value2 = 7.00D;
result = client.Divide(value1, value2);
Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
client.Close();
Console.WriteLine();
Console.WriteLine("Press <ENTER> to terminate client.");
Console.ReadLine();
}
示例10: Main
static void Main(string[] args)
{
CalculatorClient client1 = new CalculatorClient("calculatorservice");
client1.Open();
CalculatorClient client2 = new CalculatorClient("calculatorservice");
client2.Open();
client1.Close();
client2.Close();
Console.WriteLine("ChannelFactory的状态: {0}", client1.ChannelFactory.State);
Console.WriteLine("ChannelFactory的状态: {0}\n", client2.ChannelFactory.State);
EndpointAddress address = new EndpointAddress("http://127.0.0.1:3721/calculatorservice");
Binding binding = new WS2007HttpBinding();
CalculatorClient client3 = new CalculatorClient(binding, address);
client3.Open();
CalculatorClient client4 = new CalculatorClient(binding, address);
client4.Open();
client3.Close();
client4.Close();
Console.WriteLine("ChannelFactory的状态: {0}", client3.ChannelFactory.State);
Console.WriteLine("ChannelFactory的状态: {0}", client4.ChannelFactory.State);
Console.Read();
}
示例11: Main
static void Main()
{
// Create a client to endpoint configuration for ICalculator
CalculatorClient client = new CalculatorClient();
Console.WriteLine("Communicate with default ICalculator endpoint.");
// call operations
DoCalculations(client);
//close client and release resources
client.Close();
//Create a client to endpoint configuration for ICalculatorSession
CalculatorSessionClient sClient = new CalculatorSessionClient();
Console.WriteLine("Communicate with ICalculatorSession endpoint.");
sClient.Clear();
sClient.AddTo(100.0D);
sClient.SubtractFrom(50.0D);
sClient.MultiplyBy(17.65D);
sClient.DivideBy(2.0D);
double result = sClient.Result();
Console.WriteLine("0, + 100, - 50, * 17.65, / 2 = {0}", result);
//close client and release resources
sClient.Close();
Console.WriteLine();
Console.WriteLine("Press <ENTER> to terminate client.");
Console.ReadLine();
}
示例12: DoCalculations
static void DoCalculations(CalculatorClient client)
{
// Call the Add service operation.
double value1 = 100.00D;
double value2 = 15.99D;
double result = client.Add(value1, value2);
Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
// Call the Subtract service operation.
value1 = 145.00D;
value2 = 76.54D;
result = client.Subtract(value1, value2);
Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);
// Call the Multiply service operation.
value1 = 9.00D;
value2 = 81.25D;
result = client.Multiply(value1, value2);
Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);
// Call the Divide service operation.
value1 = 22.00D;
value2 = 7.00D;
result = client.Divide(value1, value2);
Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
}
示例13: Main
static void Main()
{
// Create a client
CalculatorClient client = new CalculatorClient("NetTcpBinding_ICalculator");
// Call the Add service operation.
double value1 = 100.00D;
double value2 = 15.99D;
double result = client.Add(value1, value2);
Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
// Call the Subtract service operation.
value1 = 145.00D;
value2 = 76.54D;
result = client.Subtract(value1, value2);
Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);
// Call the Multiply service operation.
value1 = 9.00D;
value2 = 81.25D;
result = client.Multiply(value1, value2);
Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);
//Closing the client gracefully closes the connection and cleans up resources
client.Close();
Console.WriteLine();
Console.WriteLine("Press <ENTER> to terminate client.");
Console.ReadLine();
}
示例14: CallService
public static void CallService(string endpointName)
{
CalculatorClient client = new CalculatorClient(endpointName);
Console.WriteLine("Calling Endpoint: {0}", endpointName);
// Call the Add service operation.
double value1 = 100.00D;
double value2 = 15.99D;
double result = client.Add(value1, value2);
Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
// Call the Subtract service operation.
value1 = 145.00D;
value2 = 76.54D;
result = client.Subtract(value1, value2);
Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);
// Call the Multiply service operation.
value1 = 9.00D;
value2 = 81.25D;
result = client.Multiply(value1, value2);
Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);
// Call the Divide service operation.
value1 = 22.00D;
value2 = 7.00D;
result = client.Divide(value1, value2);
Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
Console.WriteLine();
client.Close();
}
示例15: Main
static void Main()
{
// Create a client to default (http) endpoint configuration
CalculatorClient client = new CalculatorClient("default");
Console.WriteLine("Communicate with http endpoint.");
// call operations
DoCalculations(client);
//Closing the client gracefully closes the connection and cleans up resources
client.Close();
// Create a client to tcp endpoint configuration
client = new CalculatorClient("tcp");
Console.WriteLine("Communicate with tcp endpoint.");
// call operations
DoCalculations(client);
client.Close();
// Create a client to named pipe endpoint configuration
client = new CalculatorClient("namedpipe");
Console.WriteLine("Communicate with named pipe endpoint.");
// call operations
DoCalculations(client);
client.Close();
Console.WriteLine();
Console.WriteLine("Press <ENTER> to terminate client.");
Console.ReadLine();
}