开发者

Silverlight Cross - Zone WCF access

I need to provide a localhost (self hosted) WCF - service for a Silverlight application. This service will provide all kinds of local functionality (legacy stuff, but also access to advanced hardware devices) to the Silverlight application.

Imagine the following situation:

Customer needs to use POS - printers in their native mode, but the application must be a Silverlight one (this is part of the requirement, it can't be discussed and / or changed - and this has very good reasons!).

So I created the clientaccesspolicy.xml and also a crossdomain.xml, but now I found out that so called "cross-zone" - calls are not allowed.

The SL - application will be hosted on a server - farm (which is clearly not in the same zone as "localhost"), while the service itself must absolutely run on localhost.

Is there ANY way to motivat开发者_Python百科e Silverlight to allow me to call a service on localhost from an application that is located on the Internet?


Please take a look on the following VS project:

http://cid-a971dd3af5c625e1.office.live.com/browse.aspx/.Public/SL%5E_DirectPrinting

It was just a silly proof of concept back when SL didn't have printing capability.

Silverlight 4 has printing capability and can also use com interop.

COM interop is Windows only and I believe so is self hosting wcf as it needs full .NET framework installed.

For the self hosting the key is to be able to serve the clientaccesspolicy.xml.

The link contains a zip file with a VS2008 solution.

The compressed file contains 3 projects:

•HostGateway.Win – A Windows forms application that exposes the services for printing and serving the client access policy file. •HostGateway.SL/SL.Web – A simple Silverlight application for testing the whole idea.

Some information on the HostGateway.Win project: - Printer.cs The class in charge of the actual printing. Really basic stuff right from the MSDN site. - PolicyRetriever.cs Service that provides the clientaccesspolicy.xml file - The clientaccesspolicy.xml content is stored as a resource. - PrinterGateway.cs Service that deals with print requests. - Form1.cs Form that hosts the WCF services.

Both services are configured by code only.

And some info on the HostGateway.SL project: - Contains a service reference to the PrinterGateway service. - MainPage consumes the services, also configured by code only.

To test the application you should:

  • Set a default printer;
  • Launch HostGateway.Win application;
  • Launch the Silverlight application;
  • Type something on the text;
  • Press the Print button;
  • Wait anxiously to see if the printer prints.

If you decide to test this, make sure the win app is running before attempting to talk to it.

If the request for the policy file fails Silverlight will not try again. That means that to get SL to reconnect to the service the SL application has to be restarted.

I hope this helps.

The following links contain info on self hosting:

http://blogs.msdn.com/b/carlosfigueira/archive/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services.aspx

http://www.code-magazine.com/article.aspx?quickid=0701041&page=1

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜