开发者

Silverlight to self hosted WCF

开发者 https://www.devze.com 2023-02-09 01:58 出处:网络
I have a silverlight application which has a WCF in it. Since it is a self hosted WCF I\'ve understand I have to add an interface something like:

I have a silverlight application which has a WCF in it. Since it is a self hosted WCF I've understand I have to add an interface something like:

[ServiceContract]
public interface IPolicyRetriever
{
    [OperationContract, WebGet(UriTemplate = "/clientaccesspolicy.xml")]
    Stream GetSilverlightPolicy();
    [OperationContract, WebGet(UriTemplate = "/crossdomain.xml")]
    Stream GetFlashPolicy();
}

and the implemetation:

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""?>
        <access-policy>
            <cross-domain-access>
                <policy>
                    <allow-from http-request-headers=""*"">
                        <domain uri=""*""/>
                    </allow-from>
                    <grant-to>
                        <resource path=""/"" include-开发者_高级运维subpaths=""true""/>
                    </grant-to>
                </policy>
            </cross-domain-access>
        </access-policy>";
        return StringToStream(result);
    }
    public Stream GetFlashPolicy()
    {
        string result = @"<?xml version=""1.0""?>
        <!DOCTYPE cross-domain-policy SYSTEM ""http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"">
        <cross-domain-policy>
            <allow-access-from domain=""*"" />
        </cross-domain-policy>";
        return StringToStream(result);
    }

but I don't understand the next steps I have to do in order the silverlight calls to WCF will not raise communcation exception.

Can you please show me the code I have to write and where? (when I google it I didn't understand when the WCF calls to retrive the clientaccesspolicy, and what is the endpoint I have to add, I'm new to silverlight and WCF and don't know exaclty why I have to add an endpoint...)

this is my ServiceReference.ClientConfig:

    <configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IMapService" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647">
                    <security mode="None" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:4693/MapService.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IMapService" contract="MapService.IMapService"
                name="BasicHttpBinding_IMapService" />
        </client>
    </system.serviceModel>
</configuration>

thank you!


Silverlight Http stack (HTTP clientaccesspolicy.xml)

Must be hosted in root of your target domain. Could be easily checked with web browser. Silverlight checks it automatically one time.

Silverlight 3 sockets (Custom policy server)

I've already made this policy server for Silverlight for Log2Console app.

I think this code may help SL Policy Server.

It has to be hosted on special port TCP port 943.

Silverligt 4 sockets (by default as in SL3, but can be opted-in for HTTP)

Set the SocketAsyncEventArgs.SocketClientAccessPolicyProtocol property on the SocketAsyncEventArgs passed to Socket.ConnectAsync to SocketClientAccessPolicyProtocol.Http.

Silverlight possible ports range

80, 443, 4502-4532 (if allowed in clientaccesspolicy.xml)

Detailed documentation

0

精彩评论

暂无评论...
验证码 换一张
取 消