0

我有一個在Windows託管服務SilverLight的連接到NetTcp WCF託管inWindows服務

它使用NetTcpBinding的,我可以接,我要實現新的Silverlight客戶端訪問服務

我有一個WCF服務通過正常的方式行走添加服務引用,並用空「ServiceReferences.ClientConfig」

,所以我觀看了一些主題和主題加入,最後我有手動寫我的配置服務

當我嘗試連接它時顯示這個異常 無法連接到net.tcp:// localhost:4502/MyService/Service。連接嘗試持續時間爲00:00:02.2111265。 TCP錯誤代碼10013:嘗試以其訪問權限禁止的方式訪問套接字。這可能是由於嘗試以跨域方式訪問服務,而服務未配置爲跨域訪問。您可能需要聯繫該服務的所有者以通過HTTP公開一個套接字跨域策略,並將該服務託管在允許的套接字端口範圍4502-4534中。

我認爲,有關ClientAccessPolicy.xml問題文件

後搜索人說我需要安裝IIS7和文件是通過它訪問,我都試過,但我不能使它工作

但是,我對這個工作過,但我是使用PollinghttpBinding沒有NetTCP,我創造了另一種服務合同返回ClientAccessPolicy文件

我試圖做同樣的我做之前,PollinghttpBinding但我可以寫出正確的服務配置

我的客戶拒絕使用IIS,那麼我可以使用這種方式,什麼是我應該使用此服務的正確配置?

這是我用我的服務

<service behaviorConfiguration="serviceBehavior" name="MyService"> 
       <endpoint address="net.tcp://localhost:4502/MyService/Service"  behaviorConfiguration="endpointBehavior" binding="netTcpBinding"   bindingConfiguration="netTcpServiceBinding" contract="IMyService"> 
        <identity> 
         <dns value="localhost"/> 
        </identity> 
       </endpoint> 
       <endpoint address="net.tcp://localhost:7000/MyService/mex"  binding="mexTcpBinding" contract="IMetadataExchange"/> 
      </service> 

配置任何人都可以給予幫助?

回答

0

在Silverlight中不支持Net.tcp綁定「開箱即用」。這就是配置爲空的原因。但是,無論如何,您可以使用customBinding並設置所需的屬性。但是,我從來沒有嘗試過這種自己。

如果這是一個跨域問題,這與ClientAccessPolicy.xml文件相關。 通常(如各種論壇上的許多地方所述),通過將文件放入網站的根目錄來解決這個問題。因此,如果您的服務在「http:// localhost/MyService」上運行,則應將該文件放在「http:// lovalhost」中。

但是,如果沒有可用的IIS,則必須以其他方式完成。您必須在Windows服務中手動創建一個端點,該文件可用。 這是一個正常的BasicHttp綁定,您可以使用「net.tcp」或「http」。

我已經成功這種方式做到了這一點:

政策接口:

using System; 
using System.IO; 
using System.ServiceModel; 
using System.ServiceModel.Web; 

namespace MyPolicyService 
{ 
    [ServiceContract] 
    public interface IPolicyRetriever 
    { 
     [OperationContract] 
     Stream GetPolicy(); 
    } 
} 

政策類:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.IO; 
using System.ServiceModel.Web; 

namespace MyPolicyService 
{ 
    public class PolicyRetrieverBase : IPolicyRetriever 
    { 
     public 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=""*"" http-methods=""*""> 
       <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"" encoding=""utf-8""?> 
<!DOCTYPE cross-domain-policy SYSTEM ""http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd""> 
<cross-domain-policy> 
    <site-control permitted-cross-domain-policies=""all""/> 
    <allow-access-from domain=""*"" secure=""false"" /> 
    <allow-http-request-headers-from domain=""*"" headers=""*"" secure=""false"" /> 
</cross-domain-policy>"; 

      return StringToStream(result); 
     } 
    } 
} 

在創建這些類,創建服務幾乎就像你開始「net.tcp」服務一樣,但當然要改變它BasicHttpBinding並使用與BasicHttpBinding相關的一些不同的行爲和屬性值(如TransferMode = Buffered等)。

這個政策服務不用說,應該在網站根目錄(http:// localhost)上啓動。 ID你有這個IIS服務器上運行,不啓動這個政策服務,因爲這將接管該地址:-)

希望得到您的正確十歲上下方向移動:-)