2009-10-23 56 views
0

我使用Silverlight 3棱鏡(CAB)與WCF從ServiceReferences.ClientConfig在WCF中動態加載.xap文件

當我打電話一棱鏡模塊中的WCF服務讀Silverlight 3中,我得到的相同的錯誤:

「在服務模型客戶端配置部分找不到引用合同'IMyService'的默認端點元素,這可能是因爲沒有找到適用於您的應用程序的配置文件或者沒有匹配此合同的終結點元素可以在客戶端元素中找到「

事實證明,它在She這是ServiceReferences.ClientConfig文件的.xap文件,不在模塊的ServiceReferences.ClientConfig文件中。我在我的Silverlight Shell應用程序中添加了我的端點並綁定到現有的ServiceReferences.ClientConfig文件(它將其稱爲它自己的WCF服務)。

然後我不得不重建Shell應用程序來爲我的Web項目的ClientBin文件夾生成新的.xap文件。

接下來,我改變了在代碼中設置服務:

// create the binding elements 
BinaryMessageEncodingBindingElement binaryMessageEncoding = new BinaryMessageEncodingBindingElement(); 
HttpTransportBindingElement httpTransport = new HttpTransportBindingElement() 
{ MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue}; 

HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement() 
{ MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue }; 

// add the binding elements into a Custom Binding 
CustomBinding customBinding; 
if (Application.Current.Host.Source.Scheme.Equals("https", StringComparison.InvariantCultureIgnoreCase)) 
{ 
    customBinding = new CustomBinding(binaryMessageEncoding, httpsTransport); 
} 
else 
{ 
    customBinding = new CustomBinding(binaryMessageEncoding, httpTransport); 
} 

// create the Endpoint URL 
EndpointAddress endpointAddress = new EndpointAddress(

"http://localhost/Test/TestModule/Test.TestModule.WCF/TestModuleService.svc"); 

// create an interface for the WCF service 
var service = new TestModuleServiceClient(customBinding, endpointAddress); 
+0

你問了個問題嗎? – TheEmirOfGroofunkistan 2009-10-23 17:59:10

回答