
Реализация клиента
CallbackHandler.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Client
{
class CallbackHandler:IFibonacchiDuplexCallback
{
public void Equals(long result) { Console.WriteLine("The result is:"+result.ToString()+Environment.NewLine); }
public void CalculationHistory(string History) { Console.WriteLine(History); }
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace Client
{
class Program
{
static void Main(string[] args)
{
InstanceContext ic = new InstanceContext(new CallbackHandler());
FibonacchiDuplexClient fdc = new FibonacchiDuplexClient(ic);
Console.WriteLine("==============================");
Console.WriteLine("Введите номер числа Фибоначчи!");
while (true) {
try
{
int number = Convert.ToInt32(Console.ReadLine());
fdc.Fibonacchi(number);
}
catch (Exception exc) {
Console.WriteLine(exc.Message);
Console.ReadLine();
return;
}
Console.WriteLine();
char ch = Console.ReadKey().KeyChar;
switch (ch) {
case 'н':
return;
case 'с':
fdc.Clear();
Console.WriteLine("==============================");
Console.WriteLine("Введите номер числа Фибоначчи!");
break;
default:
Console.WriteLine("==============================");
Console.WriteLine("Введите номер числа Фибоначчи!");
break;
}
}
}
}
}
Код, сгенерированный командой
svcutil http://localhost:4444//o:ServiceProxy.cs /config:App.Config /n:*,Client
через командную строку VS2010:
ServiceProxy.cs
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.269
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Client
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://Bocharov.com", ConfigurationName="Client.IFibonacchiDuplex", CallbackContract=typeof(Client.IFibonacchiDuplexCallback), SessionMode=System.ServiceModel.SessionMode.Required)]
public interface IFibonacchiDuplex
{
[System.ServiceModel.OperationContractAttribute(IsOneWay=true, Action="http://Bocharov.com/IFibonacchiDuplex/Clear")]
void Clear();
[System.ServiceModel.OperationContractAttribute(IsOneWay=true, Action="http://Bocharov.com/IFibonacchiDuplex/Fibonacchi")]
void Fibonacchi(int n);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface IFibonacchiDuplexCallback
{
[System.ServiceModel.OperationContractAttribute(IsOneWay=true, Action="http://Bocharov.com/IFibonacchiDuplex/Equals")]
void Equals(long result);
[System.ServiceModel.OperationContractAttribute(IsOneWay=true, Action="http://Bocharov.com/IFibonacchiDuplex/CalculationHistory")]
void CalculationHistory(string eqn);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface IFibonacchiDuplexChannel : Client.IFibonacchiDuplex, System.ServiceModel.IClientChannel
{
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class FibonacchiDuplexClient : System.ServiceModel.DuplexClientBase<Client.IFibonacchiDuplex>, Client.IFibonacchiDuplex
{
public FibonacchiDuplexClient(System.ServiceModel.InstanceContext callbackInstance) :
base(callbackInstance)
{
}
public FibonacchiDuplexClient(System.ServiceModel.InstanceContext callbackInstance, string endpointConfigurationName) :
base(callbackInstance, endpointConfigurationName)
{
}
public FibonacchiDuplexClient(System.ServiceModel.InstanceContext callbackInstance, string endpointConfigurationName, string remoteAddress) :
base(callbackInstance, endpointConfigurationName, remoteAddress)
{
}
public FibonacchiDuplexClient(System.ServiceModel.InstanceContext callbackInstance, string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(callbackInstance, endpointConfigurationName, remoteAddress)
{
}
public FibonacchiDuplexClient(System.ServiceModel.InstanceContext callbackInstance, System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(callbackInstance, binding, remoteAddress)
{
}
public void Clear()
{
base.Channel.Clear();
}
public void Fibonacchi(int n)
{
base.Channel.Fibonacchi(n);
}
}
}
App.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IFibonacchiDuplex" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" clientBaseAddress="http://localhost:5000">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:4444/" binding="wsDualHttpBinding"
bindingConfiguration="WSDualHttpBinding_IFibonacchiDuplex"
contract="Client.IFibonacchiDuplex" name="WSDualHttpBinding_IFibonacchiDuplex">
<identity>
<userPrincipalName value="iboch-asus\ivan-bocharov" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Получим WSDL созданного сервиса: