Note
ãã®ãã¼ã¸ã«ã¢ã¯ã»ã¹ããã«ã¯ãæ¿èªãå¿ è¦ã§ãã ãµã¤ã³ã¤ã³ã¾ãã¯ãã£ã¬ã¯ããªã®å¤æ´ã試ããã¨ãã§ãã¾ãã
ãã®ãã¼ã¸ã«ã¢ã¯ã»ã¹ããã«ã¯ãæ¿èªãå¿ è¦ã§ãã ãã£ã¬ã¯ããªã®å¤æ´ã試ããã¨ãã§ãã¾ãã
ChannelFactory<TChannel> ã¸ã§ããªã㯠ã¯ã©ã¹ã¯ãè¤æ°ãã£ãã«ã®ä½æã«ä½¿ç¨ã§ãããã£ãã« ãã¡ã¯ããªã®ä½æãå¿ è¦ã¨ããé«åº¦ãªã·ããªãªã§ä½¿ç¨ãã¾ãã
ChannelFactory ã¯ã©ã¹ã®ä½ææ¹æ³ã¨ä½¿ç¨æ¹æ³
-
Windows Communication Foundation (WCF) ãµã¼ãã¹ãæ§ç¯ããå®è¡ãã¾ãã 詳細ã«ã¤ãã¦ã¯ãããµã¼ãã¹ã®è¨è¨ã¨å®è£ ãããµã¼ãã¹ã®æ§æã«é¢ããè¨äºãããã³ããã¹ãã£ã³ã° ãµã¼ãã¹ããåç §ãã¦ãã ããã
-
ServiceModel ã¡ã¿ãã¼ã¿ ã¦ã¼ãã£ãªã㣠ãã¼ã« (Svcutil.exe) ã使ç¨ãã¦ãã¯ã©ã¤ã¢ã³ãã®ã³ã³ãã©ã¯ã (ã¤ã³ã¿ã¼ãã§ã¤ã¹) ãçæãã¾ãã
ã¯ã©ã¤ã¢ã³ã ã³ã¼ãå ã§ãChannelFactory<TChannel> ã¯ã©ã¹ã使ç¨ãã¦è¤æ°ã®ã¨ã³ããã¤ã³ã ãªã¹ãã¼ã使ãã¾ãã
ä¾
using System;
using System.ServiceModel;
// This code generated by svcutil.exe.
[ServiceContract()]
interface IMath
{
[OperationContract()]
double Add(double A, double B);
}
public class Math : IMath
{
public double Add(double A, double B)
{
return A + B;
}
}
public sealed class Test
{
static void Main()
{
// Code not shown.
}
public void Run()
{
// This code is written by an application developer.
// Create a channel factory.
BasicHttpBinding myBinding = new BasicHttpBinding();
EndpointAddress myEndpoint = new EndpointAddress("http://localhost/MathService/Ep1");
ChannelFactory<IMath> myChannelFactory = new ChannelFactory<IMath>(myBinding, myEndpoint);
// Create a channel.
IMath wcfClient1 = myChannelFactory.CreateChannel();
double s = wcfClient1.Add(3, 39);
Console.WriteLine(s.ToString());
((IClientChannel)wcfClient1).Close();
// Create another channel.
IMath wcfClient2 = myChannelFactory.CreateChannel();
s = wcfClient2.Add(15, 27);
Console.WriteLine(s.ToString());
((IClientChannel)wcfClient2).Close();
myChannelFactory.Close();
}
}
Imports System.ServiceModel
' This code generated by svcutil.exe.
<ServiceContract()> _
Interface IMath
<OperationContract()> _
Function Add(a As Double, b As Double) As Double
End Interface
Public Class Math
Implements IMath
Function Add(a As Double, b As Double) As Double Implements IMath.Add
Return a + b
End Function
End Class
Public Class Test
Public Shared Sub Main()
End Sub
Public Sub Run()
' This code is written by an application developer.
' Create a channel factory.
Dim myBinding As New BasicHttpBinding
Dim myEndpoint As New EndpointAddress("http://localhost/MathService/Ep1")
Dim myChannelFactory As New ChannelFactory(Of IMath)(myBinding, myEndpoint)
' Create a channel.
Dim wcfClient1 As IMath = myChannelFactory.CreateChannel()
Dim s As Integer = wcfClient1.Add(3, 39)
Console.WriteLine(s.ToString())
Dim clientChannel As IClientChannel = CType(wcfClient1, IClientChannel)
clientChannel.Close()
' Create another channel
Dim wcfClient2 As IMath = myChannelFactory.CreateChannel()
s = wcfClient2.Add(15, 27)
Console.WriteLine(s.ToString())
clientChannel = CType(wcfClient2, IClientChannel)
clientChannel.Close()
myChannelFactory.Close()
End Sub
End Class