我有一個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>
謝謝!
你能給我一個例子網址您的服務運行? (即http://myapp.com/service.svc)?我可以更好地讓你的答案。隨意抽象任何你需要的,只是一個例子,你可以從中導出你的解決方案 – 2011-02-06 17:07:09
@泰勒:這裏是一個例子:http:// localhost:4693/MapService.svc – gln 2011-02-06 19:07:13