private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration) { if ((endpointConfiguration == EndpointConfiguration.CTProductsInStockSoap)) { System.ServiceModel.BasicHttpsBinding result = new System.ServiceModel.BasicHttpsBinding(); result.MaxBufferSize = int.MaxValue; result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max; result.MaxReceivedMessageSize = int.MaxValue; result.AllowCookies = true; result.SendTimeout = new System.TimeSpan(0, 5, 0); result.ReceiveTimeout = new System.TimeSpan(0, 5, 0); return(result); } if ((endpointConfiguration == EndpointConfiguration.CTProductsInStockSoap12)) { 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)); }
static void Main(string[] args) { //string wsSPCUrl = "https://treina.spc.org.br/spc/remoting/ws/consulta/consultaWebService"; //string wsSPCUsuario = "400136"; //string wsSPCSenha = "27072020"; //SPCService service = new SPCService(wsSPCUrl, wsSPCUsuario, wsSPCSenha); //var retorno = service.Consultar(ClassificacaoFiscal.PJ, "02178451000149"); var binding = new System.ServiceModel.BasicHttpsBinding(); binding.MaxReceivedMessageSize = 65536 * 30; binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Basic; var address = new System.ServiceModel.EndpointAddress("https://treina.spc.org.br/spc/remoting/ws/consulta/consultaWebService"); using (var serv = new WsSPCTeste.consultaWebServiceClient(binding, address)) { serv.ClientCredentials.UserName.UserName = "******"; serv.ClientCredentials.UserName.Password = "******"; serv.Open(); //var result = serv.sobreWebService(); var filtro = new WsSPCTeste.FiltroConsulta { codigoproduto = "198", tipoconsumidor = WsSPCTeste.TipoPessoa.J, tipoconsumidorSpecified = true, documentoconsumidor = "02178451000149" }; try { var res = serv.consultar(filtro); Console.ReadKey(); } catch (Exception ex) { throw; } //var res = serv.listarProdutos(); Console.ReadKey(); } //WsSPCTeste.consultaWebServiceClient ws = new WsSPCTeste.consultaWebServiceClient(); //ws.ClientCredentials.UserName.UserName = "******"; // ws.ClientCredentials.UserName.Password = "******"; //var res = ws.consultar(new WsSPCTeste.FiltroConsulta //{ // codigoproduto = "198", // tipoconsumidor = WsSPCTeste.TipoPessoa.J, // documentoconsumidor = "02178451000149" //}); Console.ReadKey(); }
private static System.ServiceModel.HttpBindingBase _initializeHttpBinding(string url, ReportViewerModel model) { if (url.ToLower().StartsWith("https")) { var binding = new System.ServiceModel.BasicHttpsBinding(System.ServiceModel.BasicHttpsSecurityMode.Transport); binding.Security.Transport.ClientCredentialType = model.ClientCredentialType; binding.MaxReceivedMessageSize = int.MaxValue; if (model.Timeout.HasValue) { if (model.Timeout == System.Threading.Timeout.Infinite) { binding.CloseTimeout = TimeSpan.MaxValue; binding.OpenTimeout = TimeSpan.MaxValue; binding.ReceiveTimeout = TimeSpan.MaxValue; binding.SendTimeout = TimeSpan.MaxValue; } else { binding.CloseTimeout = new TimeSpan(0, 0, model.Timeout.Value); binding.OpenTimeout = new TimeSpan(0, 0, model.Timeout.Value); binding.ReceiveTimeout = new TimeSpan(0, 0, model.Timeout.Value); binding.SendTimeout = new TimeSpan(0, 0, model.Timeout.Value); } } return(binding); } else { var binding = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly); binding.Security.Transport.ClientCredentialType = model.ClientCredentialType; binding.MaxReceivedMessageSize = int.MaxValue; if (model.Timeout.HasValue) { if (model.Timeout == System.Threading.Timeout.Infinite) { binding.CloseTimeout = TimeSpan.MaxValue; binding.OpenTimeout = TimeSpan.MaxValue; binding.ReceiveTimeout = TimeSpan.MaxValue; binding.SendTimeout = TimeSpan.MaxValue; } else { binding.CloseTimeout = new TimeSpan(0, 0, model.Timeout.Value); binding.OpenTimeout = new TimeSpan(0, 0, model.Timeout.Value); binding.ReceiveTimeout = new TimeSpan(0, 0, model.Timeout.Value); binding.SendTimeout = new TimeSpan(0, 0, model.Timeout.Value); } } return(binding); } }
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration) { if ((endpointConfiguration == EndpointConfiguration.ModificaDocumento)) { System.ServiceModel.BasicHttpsBinding result = new System.ServiceModel.BasicHttpsBinding(); result.MaxBufferSize = int.MaxValue; result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max; result.MaxReceivedMessageSize = int.MaxValue; result.AllowCookies = true; return(result); } throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration)); }
private void eBayAPIInstance() { var binding = new System.ServiceModel.BasicHttpsBinding() { //CloseTimeout = TimeSpan.FromMilliseconds(Timeout), MaxBufferPoolSize = int.MaxValue, MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue }; var endpointAddress = new System.ServiceModel.EndpointAddress("https://api.ebay.com/wsapi"); channelFactory = new System.ServiceModel.ChannelFactory <Core.Soap.eBayAPIInterface>(binding, endpointAddress); //var 报文 = new Core.Sdk.报文(); channelFactory.Endpoint.EndpointBehaviors.Add(new Core.Sdk.ContextPropagationBehavior(SoapMessage)); }
public void BasicHttpsRequestReplyEchoString() { string testString = new string('a', 3000); IWebHost host = ServiceHelper.CreateHttpsWebHostBuilder <Startup>(_output).Build(); using (host) { host.Start(); System.ServiceModel.BasicHttpsBinding httpsBinding = ClientHelper.GetBufferedModeHttpsBinding(); var factory = new System.ServiceModel.ChannelFactory <ClientContract.IEchoService>(httpsBinding, new System.ServiceModel.EndpointAddress(new Uri("https://localhost:8443/BasicWcfService/basichttp.svc"))); factory.Credentials.ServiceCertificate.SslCertificateAuthentication = new System.ServiceModel.Security.X509ServiceCertificateAuthentication { CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None }; ClientContract.IEchoService channel = factory.CreateChannel(); string result = channel.EchoString(testString); Assert.Equal(testString, result); } }
private static Binding GetBinding(string scheme) { if ("https".Equals(scheme, StringComparison.InvariantCultureIgnoreCase)) { System.ServiceModel.BasicHttpsBinding result = new System.ServiceModel.BasicHttpsBinding(); result.MaxBufferSize = int.MaxValue; result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max; result.MaxReceivedMessageSize = int.MaxValue; result.AllowCookies = true; return(result); } else { 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); } }
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration, System.TimeSpan timeout) { var binding = new System.ServiceModel.BasicHttpsBinding(); if (endpointConfiguration == EndpointConfiguration.VoidPort) { binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Basic; binding.Security.Mode = System.ServiceModel.BasicHttpsSecurityMode.Transport; var integerMaxValue = int.MaxValue; binding.MaxBufferSize = integerMaxValue; binding.MaxReceivedMessageSize = integerMaxValue; binding.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max; binding.AllowCookies = true; binding.ReceiveTimeout = timeout; binding.SendTimeout = timeout; binding.OpenTimeout = timeout; binding.CloseTimeout = timeout; } return(binding); }
public WsSPC.ResultadoConsulta Consultar(TipoPessoaResponse tipo, string documento, string codigoProduto) { TipoPessoa tipoPessoa = tipo == TipoPessoaResponse.PessoaFisica ? WsSPC.TipoPessoa.F : WsSPC.TipoPessoa.J; var binding = new System.ServiceModel.BasicHttpsBinding(); binding.MaxReceivedMessageSize = 65536 * 30; binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Basic; var address = new System.ServiceModel.EndpointAddress(_url); using (var serv = new WsSPC.consultaWebServiceClient(binding, address)) { serv.ClientCredentials.UserName.UserName = _usuario; serv.ClientCredentials.UserName.Password = _senha; serv.Open(); var filtro = new WsSPC.FiltroConsulta { codigoproduto = codigoProduto, tipoconsumidor = tipoPessoa, tipoconsumidorSpecified = true, documentoconsumidor = documento }; try { return(serv.consultar(filtro)); } catch (Exception ex) { throw new Exception(ex.Message); } } }
static void Connect(string url, string username, string password, string ip) { try { //Disable SSL Log("[x] Disabling SSL checks in case vCenter is using untrusted/self-signed certificates"); System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true); //Create the vCenter API object Log("[x] Creating vSphere API interface, takes a few minutes..."); binding = new System.ServiceModel.BasicHttpsBinding { AllowCookies = true }; binding.Security.Mode = System.ServiceModel.BasicHttpsSecurityMode.Transport; var endpoint = new System.ServiceModel.EndpointAddress(url); vim = new VimPortTypeClient(binding, endpoint); var moref = new ManagedObjectReference { type = "ServiceInstance", Value = "ServiceInstance", }; //Bind to vCenter serviceContent = vim.RetrieveServiceContent(moref); Log("[x] Connected to " + serviceContent.about.fullName); //Attempt login if (username != null) { //Login with username and password userSession = vim.Login(serviceContent.sessionManager, username, password, null); } /*else * { * //Login with SSPI * byte[] rawToken = GetSSPIToken(PackageNames.Kerberos); * string token = Convert.ToBase64String(rawToken); * var token2 = System.Text.Encoding.Default.GetString(rawToken); * try * { * vim.LoginBySSPI(serviceContent.sessionManager, token, null); * } * catch (Exception exception) * { * Console.Out.WriteLine(exception.ToString()); * } * * }*/ if (userSession is null) { Error(new Exception("Failed to authenticate.")); } Log("[x] Successfully authenticated"); //Retrieve filemanager guestFileManager = GetProperty <ManagedObjectReference>(serviceContent.guestOperationsManager, "fileManager"); if (guestFileManager is null) { Error(new Exception("Failed to retrieve filemanager")); } //Get the current session and check it's valid UserSession currentSession = GetProperty <UserSession>(serviceContent.sessionManager, "currentSession"); if (currentSession is null || currentSession.key != userSession.key) { Error(new Exception("Failed to retrieve current session")); } //Retrieve target VM if (ip != null) { vm = vim.FindByIp(serviceContent.searchIndex, null, ip, true); } } catch (Exception fault) //Generic catch all { Error(fault); } }
private static System.ServiceModel.HttpBindingBase _initializeHttpBinding(string url, ReportViewerModel model) { if (url.ToLower().StartsWith("https")) { var binding = new System.ServiceModel.BasicHttpsBinding(System.ServiceModel.BasicHttpsSecurityMode.Transport); binding.Security.Transport.ClientCredentialType = model.ClientCredentialType; // System.ServiceModel.HttpClientCredentialType.Ntlm; // model.ClientCredentialType; binding.MaxReceivedMessageSize = int.MaxValue; // 10MB size limit on response to allow for larger PDFs (Valor por defecto: 65536) if (model.Timeout.HasValue) { if (model.Timeout == System.Threading.Timeout.Infinite) { binding.CloseTimeout = TimeSpan.MaxValue; binding.OpenTimeout = TimeSpan.MaxValue; binding.ReceiveTimeout = TimeSpan.MaxValue; binding.SendTimeout = TimeSpan.MaxValue; } else { binding.CloseTimeout = new TimeSpan(0, 0, model.Timeout.Value); binding.OpenTimeout = new TimeSpan(0, 0, model.Timeout.Value); binding.ReceiveTimeout = new TimeSpan(0, 0, model.Timeout.Value); binding.SendTimeout = new TimeSpan(0, 0, model.Timeout.Value); } } else { binding.CloseTimeout = TimeSpan.MaxValue; binding.OpenTimeout = TimeSpan.MaxValue; binding.ReceiveTimeout = TimeSpan.MaxValue; binding.SendTimeout = TimeSpan.MaxValue; } return(binding); } else { var binding = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly); binding.Security.Transport.ClientCredentialType = model.ClientCredentialType; // System.ServiceModel.HttpClientCredentialType.Ntlm; // model.ClientCredentialType; binding.MaxReceivedMessageSize = int.MaxValue; // 10MB size limit on response to allow for larger PDFs (Valor por defecto: 65536) if (model.Timeout.HasValue) { if (model.Timeout == System.Threading.Timeout.Infinite) { binding.CloseTimeout = TimeSpan.MaxValue; binding.OpenTimeout = TimeSpan.MaxValue; binding.ReceiveTimeout = TimeSpan.MaxValue; binding.SendTimeout = TimeSpan.MaxValue; } else { binding.CloseTimeout = new TimeSpan(0, 0, model.Timeout.Value); binding.OpenTimeout = new TimeSpan(0, 0, model.Timeout.Value); binding.ReceiveTimeout = new TimeSpan(0, 0, model.Timeout.Value); binding.SendTimeout = new TimeSpan(0, 0, model.Timeout.Value); } } else { binding.CloseTimeout = TimeSpan.MaxValue; binding.OpenTimeout = TimeSpan.MaxValue; binding.ReceiveTimeout = TimeSpan.MaxValue; binding.SendTimeout = TimeSpan.MaxValue; } return(binding); } }