示例#1
0
 /// <summary>
 /// Gets the absolute URL for a service
 /// </summary>
 /// <param name="device">UPnP device to control</param>
 /// <param name="service">UPnP service</param>
 /// <returns>the absolute URL for the service</returns>
 protected Uri GetControlUri(Device device, Service service)
 {
     var requestUri = new Uri(service.ControlURL, UriKind.RelativeOrAbsolute);
     if (!requestUri.IsAbsoluteUri || requestUri.IsFile) // In Mono.Android, requestUri is not a relative uri but a file
     {
         requestUri = new Uri(new Uri(device.URLBase), requestUri);
     }
     return requestUri;
 }
示例#2
0
 private IService ConvertService(UPnP.Service service)
 {
     if (service.ServiceId == ContentDirectory.Service.ServiceId)
     {
         return new ContentDirectory.Service(this, service);
     }
     else
     {
         // ignore unsupported service.
         return null;
     }
 }
示例#3
0
        /// <summary>
        /// Action call
        /// </summary>
        /// <param name="httpClient">HTTPClient</param>
        /// <param name="service">UPnP service</param>
        /// <param name="controlURL">control URL</param>
        /// <param name="action">action</param>
        /// <param name="headers">optional HTTP headers</param>
        /// <returns>HTTP response message</returns>
        protected async Task<HttpResponseMessage> PostActionAsync(HttpClient httpClient, Service service, Uri controlURL, object action,
            params Tuple<string, string>[] headers)
        {
            var xmlRootAttribute = action.GetType().GetTypeInfo().GetCustomAttribute<XmlRootAttribute>();
            xmlRootAttribute.Namespace = service.ServiceType;
            var request = new StringContent(String.Format(SOAP_ENVELOPE, XmlSerializerUtility.Serialize(action, xmlRootAttribute,
                new XmlQualifiedName("u", service.ServiceType))), Encoding.UTF8, "text/xml");
            request.Headers.Add("SOAPAction", $"\"{service.ServiceType}#{xmlRootAttribute.ElementName}\"");
            if (headers != null)
            {
                foreach (var header in headers)
                {
                    request.Headers.Add(header.Item1, header.Item2);
                }
            }

            return await httpClient.PostAsync(controlURL, request);
        }