var client = new DailyInfoSoapClient(DailyInfoSoapClient.EndpointConfiguration.DailyInfoSoap);
public enum EndpointConfiguration { DailyInfoSoap, DailyInfoSoap12, }
public DailyInfoSoapClient(EndpointConfiguration endpointConfiguration) : base(DailyInfoSoapClient.GetBindingForEndpoint(endpointConfiguration), DailyInfoSoapClient.GetEndpointAddress(endpointConfiguration)) { this.Endpoint.Name = endpointConfiguration.ToString(); ConfigureEndpoint(this.Endpoint, this.ClientCredentials); }
// , . . static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials); private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration) { if ((endpointConfiguration == EndpointConfiguration.DailyInfoSoap)) { System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding(); result.MaxBufferSize = int.MaxValue; result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max; result.MaxReceivedMessageSize = int.MaxValue; result.AllowCookies = true; return result; } if ((endpointConfiguration == EndpointConfiguration.DailyInfoSoap12)) { System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding(); System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement(); textBindingElement.MessageVersion = System.ServiceModel.Channels.MessageVersion.CreateVersion(System.ServiceModel.EnvelopeVersion.Soap12, System.ServiceModel.Channels.AddressingVersion.None); result.Elements.Add(textBindingElement); System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement(); httpBindingElement.AllowCookies = true; httpBindingElement.MaxBufferSize = int.MaxValue; httpBindingElement.MaxReceivedMessageSize = int.MaxValue; result.Elements.Add(httpBindingElement); return result; } throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration)); } private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration) { if ((endpointConfiguration == EndpointConfiguration.DailyInfoSoap)) { return new System.ServiceModel.EndpointAddress("http://www.cbr.ru/DailyInfoWebServ/DailyInfo.asmx"); } if ((endpointConfiguration == EndpointConfiguration.DailyInfoSoap12)) { return new System.ServiceModel.EndpointAddress("http://www.cbr.ru/DailyInfoWebServ/DailyInfo.asmx"); } throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration)); }
var dataset = await client.EnumValutesAsync(false);
var uri = new Uri(@"http://services.odata.org/V4/OData/OData.svc/"); var client = new ODataDemo.DemoService(uri); client.Format.UseJson();
var products = client.Products.Expand(p => p.Supplier); foreach (var p in products) { Console.WriteLine("{0}\t{1}\t{2}", p.Name, p.Price, p.Supplier.Name); }
The required version of the .NET Framework does not allow direct data transfer at the request of the data transmission service. This is due to the fact that when you transfer to the data service, a synchronous request is automatically sent. Since this version of the .NET Framework only supports asynchronous operations, you must instead call the BeginExecute and EndExecute methods to get the result of a query that supports enumeration.
var query = container.Products.Expand("ProductDetail,Categories"); System.AsyncCallback OnCustomersQueryComplete = (result => { foreach (var product in query.EndExecute(result)) { DisplayProduct(product); } }); query.BeginExecute(OnCustomersQueryComplete, query);
public static async Task<IEnumerable<TResult>> ExecuteAsync<TResult>(this DataServiceQuery<TResult> query) { var queryTask = Task.Factory.FromAsync<IEnumerable<TResult>>(query.BeginExecute(null, null), (queryAsyncResult) => { var results = query.EndExecute(queryAsyncResult); return results; }); return await queryTask; }
public Task<IEnumerable<TElement>> ExecuteAsync();
var query = container.Products.Expand("Supplier,Categories"); //https://blogs.msdn.microsoft.com/writingdata_services/2013/03/04/extending-the-odata-async-extensions-to-dataservicecollectiont-methods/ //http://odata.imtqy.com/odata.net/#OData-Client-Code-Generation-Tool var result = await query.ExecuteAsync(); foreach (var product in result) { DisplayProduct(product); }
Source: https://habr.com/ru/post/310152/
All Articles