Silverlight自我托管WCF
问题描述:
我有一个Silverlight应用程序,它有一个WCF。 既然是自承载的WCF我已经明白我要补充的接口是这样的:Silverlight自我托管WCF
[ServiceContract]
public interface IPolicyRetriever
{
[OperationContract, WebGet(UriTemplate = "/clientaccesspolicy.xml")]
Stream GetSilverlightPolicy();
[OperationContract, WebGet(UriTemplate = "/crossdomain.xml")]
Stream GetFlashPolicy();
}
和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);
}
,但我不知道接下来该我有为了让Silverlight调用WCF不会增加通信异常。
你能告诉我我必须写的代码和位置吗? (当我谷歌它我不明白什么时候WCF调用回顾clientaccesspolicy,什么是端点我不得不添加,我是silverlight和WCF的新手,不知道为什么我必须添加一个端点......)
这是我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>
谢谢!
答
的Silverlight HTTP栈(HTTP clientaccesspolicy.xml)
必须在目标域的根主持。可以使用网络浏览器轻松检查。 Silverlight会自动检查一次。
Silverlight 3的插座(自定义策略服务器)
我已经作好了Silverlight的应用Log2Console这个策略服务器。
我认为这段代码可能有帮助SL Policy Server。
它以特殊端口的TCP端口托管943
Silverligt 4个插槽(默认情况下为SL3,但可以选择支持HTTP)
设置SocketAsyncEventArgs.SocketClientAccessPolicyProtocol将SocketAsyncEventArgs的属性传递给Socket.ConnectAsync传递给SocketClientAccessPolicyProtocol.Http。
Silverlight的可能端口范围
80,443,4502-4532(如果允许在clientaccesspolicy.xml)
你能给我一个例子网址您的服务运行? (即http://myapp.com/service.svc)?我可以更好地让你的答案。随意抽象任何你需要的,只是一个例子,你可以从中导出你的解决方案 – 2011-02-06 17:07:09
@泰勒:这里是一个例子:http:// localhost:4693/MapService.svc – gln 2011-02-06 19:07:13