从动态加载的 .xap 文件中 Silverlight 3 中的 WCF 中的 ServiceReferences.ClientConfig 读取

发布于 2024-08-08 13:21:41 字数 1579 浏览 4 评论 0原文

我将 Silverlight 3 Prism (CAB) 与 WCF 结合使用

当我在 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);

I'm using Silverlight 3 Prism (CAB) with WCF

When I call a WCF service in a Prism module, I get the same error:

"Could not find default endpoint element that references contract 'IMyService' in the service model client configuaration section. This might be because no configuaration file was found for your application or because no end point element matching this contract could be found in the client element"

It turns out that its looking in the Shell's .xap file for a ServiceReferences.ClientConfig file, not in the module's ServiceReferences.ClientConfig file. I added my endpoint and binding to the existing ServiceReferences.ClientConfig file in my Silverlight Shell application (it calls it's own WCF services).

Then I had to rebuild the Shell app to generate the new .xap file for my Web project's ClientBin folder.

Next I changed to setting up the service in code:

// 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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文