silverlight动态调用WCF服务解决办法

 

Uri uri = Application.Current.Host.Source;


ServicesInfo.BaseUrl = uri.ToString().Replace("ClientBin/SilverlightApplication4.xap", "") + "Service1.svc";

HttpTransportBindingElement httpTransport = new HttpTransportBindingElement();
httpTransport.MaxReceivedMessageSize = 2147483647;
httpTransport.MaxBufferSize = 2147483647;

BinaryMessageEncodingBindingElement binaryEle = new BinaryMessageEncodingBindingElement();

CustomBinding binding = new CustomBinding(binaryEle, httpTransport);
binding.Name = "CustomBinding_SilverLightService";
return new DataService.Service1Client(binding, new EndpointAddress(ServicesInfo.BaseUrl));

 

另外一种解决方案

DataService.Service1Client client = new DataService.Service1Client();
client.Endpoint.Address = new EndpointAddress(ServicesInfo.BaseUrl);
client.OpenAsync();

你可能感兴趣的:(silverlight动态调用WCF服务解决办法)