1 // Copyright 2003-2004 DigitalCraftsmen - http://www.digitalcraftsmen.com.br/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.ManagementExtensions
.Remote
.Providers
18 using System
.Collections
.Specialized
;
20 using System
.Runtime
.Remoting
;
21 using System
.Runtime
.Remoting
.Channels
;
22 using System
.Runtime
.Remoting
.Channels
.Http
;
24 using Castle
.ManagementExtensions
.Remote
.Server
;
25 using Castle
.ManagementExtensions
.Remote
.Client
;
28 /// Summary description for HttpChannelProvider.
30 public class HttpChannelProvider
: AbstractServerProvider
32 public HttpChannelProvider()
36 protected override bool AcceptsChannel(String channel
)
38 return "http".EndsWith(channel
);
41 protected override bool AcceptsFormatter(String formatter
)
43 return "binary".EndsWith(formatter
) || "soap".EndsWith(formatter
);
46 #region MProvider Members
48 public override MConnector
Connect(String url
, System
.Collections
.Specialized
.NameValueCollection properties
)
50 String
[] parts
= StripUrl(url
);
52 String formatter
= parts
[2];
53 String objectUri
= parts
[3];
54 String objectUrl
= null;
56 HttpClientChannel channel
= new HttpClientChannel();
60 ChannelServices
.RegisterChannel( channel
);
62 catch(RemotingException
)
67 objectUrl
= String
.Format("{0}://{1}:{2}/{3}",
68 "http", GetHost(properties
), GetPort(properties
), objectUri
);
70 object ret
= RemotingServices
.Connect( typeof(MServer
), objectUrl
, null );
72 return new MConnector( (MServer
) ret
, channel
);
77 #region MServerProvider Members
79 public override MConnectorServer
CreateServer(String url
, NameValueCollection properties
, MServer server
)
81 String
[] parts
= StripUrl(url
);
82 String formatter
= parts
[2];
83 String objectUri
= parts
[3];
85 HttpChannel channel
= CreateChannel(formatter
, properties
, true);
87 MConnectorServer connServer
= null;
91 connServer
= new MConnectorServer(server
, objectUri
);
95 connServer
= new MConnectorServer(objectUri
);
98 //connServer.Channel = channel;
105 private HttpChannel
CreateChannel(String formatter
, NameValueCollection properties
, bool createAsServer
)
107 HttpChannel httpChannel
= null;
109 int portNum
= GetPort(properties
);
111 bool alreadyRegistered
= false;
113 foreach(IChannel channel
in ChannelServices
.RegisteredChannels
)
115 if (channel
.ChannelName
.Equals("http"))
117 HttpChannel item
= (HttpChannel
) channel
;
118 ChannelDataStore dataStore
= (ChannelDataStore
) item
.ChannelData
;
119 // TODO: Check if is the same channel as the url specify
123 alreadyRegistered
= true;
128 if (!alreadyRegistered
)
132 httpChannel
= new HttpChannel(portNum
);
136 httpChannel
= new HttpChannel();
139 ChannelServices
.RegisterChannel( httpChannel
);