SEModCommunity / SE-Community-Mod-API

Space Engineers Community Modding API
GNU Lesser General Public License v3.0
60 stars 47 forks source link

WCF and silverlight #159

Closed LordXaosa closed 9 years ago

LordXaosa commented 9 years ago

I noticed, that there is an implementation of WCF services, so I decided to make little web tool with silverlight. I stucked at error, that my SL app using cross-domain requests and it's not allowed. I fixed it with some code rewritings: at first I rewrite WsHttpBind to basicHttpBind, it's important to SL, because it can't work with WsHttpBinds. Then I fixed web service with this code: private bool SetupWebService() { Uri webServiceAddress = new Uri("http://externalIp:" + WCFPort.ToString()); m_webHost = new WebServiceHost(typeof(WebService), webServiceAddress); try { WebHttpBinding binding = new WebHttpBinding(WebHttpSecurityMode.TransportCredentialOnly);; ServiceEndpoint endpoint = m_webHost.AddServiceEndpoint(typeof(IPolicyRetriever), binding, "");

            m_webHost.SetEndpointAddress(endpoint,"");
            m_webHost.Open();
        }
        catch (CommunicationException ex)
        {
            Console.WriteLine("An exception occurred: {0}", ex.Message);
            m_webHost.Abort();
            return false;
        }

        return true;
    }

Than I made an Interface for services: [ServiceContract] public interface IPolicyRetriever { [OperationContract, WebGet(UriTemplate = "/clientaccesspolicy.xml")] Stream GetSilverlightPolicy(); [OperationContract, WebGet(UriTemplate = "/crossdomain.xml")] Stream GetFlashPolicy(); }

After it I fixed all services by adding inheriting of this interface and add implementation of it to every of 5 services: Stream StringToStream(string result) { WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml"; return new MemoryStream(Encoding.UTF8.GetBytes(result)); } public Stream GetSilverlightPolicy() { string result = @"<?xml version=""1.0"" encoding=""utf-8""?>

"; return StringToStream(result); } public Stream GetFlashPolicy() { string result = @" "; return StringToStream(result); } So the main goal is when SL app asks http://domain:8000/clientaccesspolicy.xml it should get this file for working properly. This manual can help to understand the reasons. Also I workaround part with config file and write endpoint config directly to code at web service section.
LordXaosa commented 9 years ago

full text here, Git cut something... https://www.dropbox.com/s/5nms9t5ux5w3paw/fixes.txt?dl=0 Please, make this fixes in your next releases. Because rewrite it every time is butt hurt))

LordXaosa commented 9 years ago

Fixed in pull request #165