[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
プログラミング、3DCGとその他いろいろについて
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
using System.ServiceModel; namespace Contracts { [ServiceContract] public interface ICalculator { //四角形の面積を計算します [OperationContract] double GetArea(Rectangle rect); } //Error! //(throws InvalidDataContractException) public class Rectangle { public double Width; public double Height; } }
using System.ServiceModel; namespace Contracts { [ServiceContract] public interface ICalculator { //四角形の面積を計算します [OperationContract] double GetArea(Rectangle rect); } [System.Serializable] public class Rectangle { public double Width; public double Height; } }
using System; using System.ServiceModel; using Contracts; namespace Server { class MyCalculator : ICalculator { public double GetArea(Rectangle rect) { return rect.Width * rect.Height; } } class Program { static void Main(string[] args) { ServiceHost serviceHost = new ServiceHost(typeof(MyCalculator)); serviceHost.AddServiceEndpoint( typeof(ICalculator), new NetTcpBinding(), "net.tcp://localhost:8001/Calculator" ); serviceHost.Open(); Console.WriteLine("サービスがオープンしました。終了するにはEnterを押してください。"); Console.ReadLine(); serviceHost.Close(); } } }
using System; using System.ServiceModel; using System.ServiceModel.Channels; using Contracts; namespace Client { class Program { static void Main(string[] args) { ICalculator remoteService = new ChannelFactory( new NetTcpBinding(), "net.tcp://localhost:8001/Calculator" ).CreateChannel(); Console.WriteLine( "2 * 3 = " + remoteService.GetArea(new Rectangle{Width = 2, Height = 3}) ); ((IChannel)remoteService).Close(); } } }
using System.ServiceModel; namespace Contracts { [ServiceContract] public interface ICalculator { //四角形の面積を計算します [OperationContract] double GetArea(Rectangle rect); } [System.Runtime.Serialization.DataContract] public class Rectangle { [System.Runtime.Serialization.DataMember] public double Width; [System.Runtime.Serialization.DataMember] public double Height; } }
using System; using System.ServiceModel; namespace Server { [ServiceContract] interface ICalculator { [OperationContract] int Add(int a, int b); } class MyCalculator : ICalculator { public int Add(int a, int b) { return a + b; } } class Program { static void Main() { ServiceHost serviceHost = new ServiceHost(typeof(MyCalculator)); serviceHost.AddServiceEndpoint( typeof(ICalculator), new NetTcpBinding(), "net.tcp://localhost:8001/Calculator" ); serviceHost.Open(); Console.WriteLine("サービスがオープンしました。終了するにはEnterを押してください。"); Console.ReadLine(); serviceHost.Close(); } } }
using System; using System.ServiceModel; using System.ServiceModel.Channels; namespace Client { [ServiceContract] interface ICalculator { [OperationContract] int Add(int a, int b); } class Program { static void Main() { ICalculator remoteCalculator = new ChannelFactory<ICalculator>( new NetTcpBinding(), "net.tcp://localhost:8001/Calculator" ).CreateChannel(); Console.WriteLine("2 + 3 = " + remoteCalculator.Add(2, 3)); ((IChannel)remoteCalculator).Close(); } } }
public ServiceHost ( Type serviceType, params Uri[] baseAddresses )
public ServiceEndpoint AddServiceEndpoint ( Type implementedContract, Binding binding, string address )
public ChannelFactory ( Binding binding, string remoteAddress )
public TChannel CreateChannel()