.Net 4 Desktop App - Silverlight 4 Compatible Service
I'm in the process of making a system for a client that manages data in a particular way. (What it does isn't really relevant to my question). The environment seems to recommend a silverlight based solution, (many possible clients) but running IIS on the accessible server could be tricky, maybe even impossible due to the restrictions, and due to the fact I can't actually access the system to make changes to the web.config, if I did get it set up. (I'd have to provide one and hope it work开发者_JAVA技巧s, and randomly guess at changes if it didn't). So I'm attempting to build the server-side stuff into a .Net 4 (WPF) app, and expose Silverlight compatible WCF services from there.
How do I expose a silverlight compatible service? By the way, I'll be getting the thing to cover port 80 to share the XAP and crossdomain.xml (and an index page). I assume I'd be wise to somehow share the service metadata through here too?
(Silverlight 4, .Net 4)
P.S. If you think the IIS config bit is ridiculous, you should see how the data is imported! :S
Thanks!
I've used net.tcp
WCF services in a Windows Service from Silverlight. This works, however, you should make sure to use a certain port range (see here).
You could also make a WCF REST-Service - in that case the port should not matter. Generally, you should not publish service meta data on the production system at all.
For anyone else wondering about this, I simply created a self-hosted WCF service. Makes a good googling point, or even here on SO.
Here's a sample of what I'm talking about though:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="BinaryHTTP">
<binaryMessageEncoding/>
<httpTransport/>
</binding>
</customBinding>
</bindings>
<services>
<service name="MyServiceClassName" behaviorConfiguration="ServiceBehaviour">
<endpoint binding="customBinding" bindingConfiguration="BinaryHTTP"
name="MainService" contract="BaseNamespace.IMyService"
address="MyService"/>
<endpoint address="" behaviorConfiguration="webHttpEnablingBehavior"
binding="webHttpBinding" contract="BaseNamespace.IClientAccessPolicy" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:80/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- Enables public metadata, good for Add Service Reference in SL -->
<serviceMetadata httpGetEnabled="True"/>
<!-- Turn this off at the production level. -->
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttpEnablingBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
This example was semi-copied from the self hosted service sample that is in the VS2010 online gallery.
The IClientAccessPolicy interface:
Imports System.ServiceModel
Imports System.ServiceModel.web
<ServiceContract()> _
Public Interface IClientAccessPolicy
<OperationContract(), WebGet(UriTemplate:="/clientaccesspolicy.xml")> _
Function GetPolicy() As IO.Stream
End Interface
Hopefully you should be able to follow that. Just make sure your core service inherits IClientAccessPolicy and returns a valid one.
精彩评论