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

在动态加载的.xap文件中读取Silverlight 3中WCF中的ServiceReferences.ClientConfig,wcf,silverlight-3.0,prism,cab,Wcf,Silverlight 3.0,Prism,Cab,我正在使用Silverlight 3棱镜(CAB)和WCF 当我调用Prism模块中的WCF服务时,我得到了相同的错误: “在服务模型客户端配置节中找不到引用约定‘IMyService’的默认终结点元素。这可能是因为找不到应用程序的配置文件,或者在客户端元素中找不到与此约定匹配的终结点元素” 结果表明,它在Shell的.xap文件中查找ServiceReferences.ClientConfig文件,而不是在模块的ServiceReferences.ClientConfig文件中。我将端点和绑定

我正在使用Silverlight 3棱镜(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);

这篇文章讨论了类似的情况:

谢谢, 达米安·申克曼