Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Tools / ManagedExtensions / ManagementExtensions / Remote / Providers / HttpChannelProvider.cs
bloba130ccfd3ad2a38adb247dcf4032ea751e9238a5
1 // Copyright 2003-2004 DigitalCraftsmen - http://www.digitalcraftsmen.com.br/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 using System;
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;
27 /// <summary>
28 /// Summary description for HttpChannelProvider.
29 /// </summary>
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();
58 try
60 ChannelServices.RegisterChannel( channel );
62 catch(RemotingException)
64 // Already registered
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 );
75 #endregion
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;
89 if (server != null)
91 connServer = new MConnectorServer(server, objectUri);
93 else
95 connServer = new MConnectorServer(objectUri);
98 //connServer.Channel = channel;
100 return connServer;
103 #endregion
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
121 httpChannel = item;
123 alreadyRegistered = true;
124 break;
128 if (!alreadyRegistered)
130 if (createAsServer)
132 httpChannel = new HttpChannel(portNum);
134 else
136 httpChannel = new HttpChannel();
139 ChannelServices.RegisterChannel( httpChannel );
142 return httpChannel;