我用的是Silverlight 3棱镜(CAB)和WCF
当我在Prism模块中调用WCF服务时,我会得到相同的错误:
“无法在服务模型客户端信任部分找到引用合同'IMyService‘的默认端点元素。这可能是因为您的应用程序没有找到信任保护文件,或者因为在客户端元素中找不到与此契约匹配的端点元素。”
事实证明,它在Shell的.xap文件中查找ServiceReferences.ClientConfig文件,而不是在模块的ServiceReferences.ClientConfig文件中。我在Silverlight Shell应用程序中添加了端点并绑定到现有的ServiceReferences.ClientConfig文件(它调用自己的WCF服务)。
然后,我必须重新构建Shell应用程序来为我的网络项目的.xap文件夹生成新的ClientBin文件。
接下来,我更改为在代码中设置服务:
// 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);发布于 2009-10-27 17:40:04
https://stackoverflow.com/questions/1614669
复制相似问题