我正在使用带有WCF的Silverlight 3 Prism(CAB)
当我在Prism模块中调用WCF服务时,我得到了同样的错误:
“无法在服务模型客户端配置部分找到引用合同'IMyService'的默认端点元素。这可能是因为没有找到您的应用程序的配置文件,或者因为没有找到与此合同匹配的端点元素客户元素“
事实证明,它在Shell的.xap文件中查找ServiceReferences.ClientConfig文件,而不是在模块的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 :(得分:1)