public void DefaultFoo() { var reqXml = @"<?xml version=""1.0"" ?> <methodCall> <methodName>Foo</methodName> <params> <param> <value><string>1234</string></value> </param> </params> </methodCall>"; Stream reqStm = new MemoryStream(Encoding.Default.GetBytes(reqXml)); XmlRpcServerProtocol svrProt = new DefaultService(); Stream respStm = svrProt.Invoke(reqStm); var rdr = new StreamReader(respStm); var response = rdr.ReadToEnd(); var respXml = @"<?xml version=""1.0""?> <methodResponse> <params> <param> <value> <string>1234</string> </value> </param> </params> </methodResponse>"; Assert.AreEqual(respXml, response); }
public void DefaultFoo() { string reqXml = @"<?xml version=""1.0"" ?> <methodCall> <methodName>Foo</methodName> <params> <param> <value><string>1234</string></value> </param> </params> </methodCall>"; Stream reqStm = new MemoryStream(ASCIIEncoding.Default.GetBytes(reqXml)); XmlRpcServerProtocol svrProt = new DefaultService(); Stream respStm = svrProt.Invoke(reqStm); StreamReader rdr = new StreamReader(respStm); string response = rdr.ReadToEnd(); string respXml = @"<?xml version=""1.0""?> <methodResponse> <params> <param> <value> <string>1234</string> </value> </param> </params> </methodResponse>"; Assert.AreEqual(respXml, response); }
public void SystemListMethods() { string reqXml = @"<?xml version=""1.0"" ?> <methodCall> <methodName>system.listMethods</methodName> <params> </params> </methodCall>"; Stream reqStm = new MemoryStream(ASCIIEncoding.Default.GetBytes(reqXml)); XmlRpcServerProtocol svrProt = new DefaultService(); Stream respStm = svrProt.Invoke(reqStm); StreamReader rdr = new StreamReader(respStm); string response = rdr.ReadToEnd(); string respXml = @"<?xml version=""1.0""?> <methodResponse> <params> <param> <value> <array> <data> <value> <string>Bar</string> </value> <value> <string>Foo</string> </value> </data> </array> </value> </param> </params> </methodResponse>"; Assert.AreEqual(respXml, response); }
/// <summary> /// Asynchronously gets an HTTP connection to an innovator instance (or proxy) at the given URL /// </summary> /// <param name="preferences">Object containing preferences for the connection</param> /// <param name="async">Whether or not to return the connection asynchronously. This is important /// as an HTTP request must be issued to determine the type of connection to create</param> /// <returns>A promise to return a connection object</returns> public static IPromise <IRemoteConnection> GetConnection(ConnectionPreferences preferences, bool async) { preferences = preferences ?? new ConnectionPreferences(); var url = preferences.Url; url = (url ?? "").TrimEnd('/'); if (url.EndsWith("Server/InnovatorServer.aspx", StringComparison.OrdinalIgnoreCase)) { url = url.Substring(0, url.Length - 21); } if (!url.EndsWith("/server", StringComparison.OrdinalIgnoreCase)) { url += "/Server"; } var configUrl = url + "/mapping.xml"; var masterService = preferences.HttpService ?? DefaultService.Invoke(); var arasSerice = preferences.HttpService ?? DefaultService.Invoke(); Func <ServerMapping, IRemoteConnection> connFactory = m => { var uri = (m.Url ?? "").TrimEnd('/'); if (!uri.EndsWith("/server", StringComparison.OrdinalIgnoreCase)) { url += "/Server"; } switch (m.Type) { case ServerType.Proxy: throw new NotSupportedException(); default: return(ArasConn(arasSerice, uri, preferences)); } }; var result = new Promise <IRemoteConnection>(); var req = new HttpRequest(); req.UserAgent = preferences.Headers.UserAgent; req.SetHeader("Accept", "text/xml"); foreach (var header in preferences.Headers.NonUserAgentHeaders()) { req.SetHeader(header.Key, header.Value); } var trace = new LogData(4, "Innovator: Try to download mapping file", Factory.LogListener) { { "url", configUrl }, }; result.CancelTarget(masterService.GetPromise(new Uri(configUrl), async, trace, req) .Progress((p, m) => result.Notify(p, m)) .Done(r => { var data = r.AsString(); if (string.IsNullOrEmpty(data)) { result.Resolve(ArasConn(arasSerice, url, preferences)); } else { try { var servers = ServerMapping.FromXml(data).ToArray(); if (servers.Length < 1) { result.Resolve(ArasConn(arasSerice, url, preferences)); } else if (servers.Length == 1) { result.Resolve(connFactory(servers.Single())); } else { foreach (var server in servers) { server.Factory = connFactory; } result.Resolve(new MappedConnection(servers, preferences.AuthCallback)); } } catch (XmlException) { result.Resolve(ArasConn(arasSerice, url, preferences)); } } }).Fail(ex => { result.Resolve(ArasConn(arasSerice, url, preferences)); })).Always(trace.Dispose); if (preferences.Credentials != null) { IRemoteConnection conn = null; return(result .Continue(c => { conn = c; return c.Login(preferences.Credentials, async); }) .Convert(u => conn)); } return(result); }