Beispiel #1
0
        public async Task CanFetchHttpHeadersAsync(bool initialYield)
        {
            string testString = new string('a', 3000);
            var    host       = ServiceHelper.CreateWebHostBuilder <Startup>(_output).Build();

            using (host)
            {
                host.Start();
                System.ServiceModel.ChannelFactory <IHttpHeadersService> factory = null;
                IHttpHeadersService channel = null;
                try
                {
                    var httpBinding = ClientHelper.GetBufferedModeBinding();
                    factory = new System.ServiceModel.ChannelFactory <IHttpHeadersService>(httpBinding,
                                                                                           new System.ServiceModel.EndpointAddress(new Uri("http://localhost:8080/BasicWcfService/httpHeaders.svc")));
                    channel = factory.CreateChannel();
                    Task <string> resultTask = null;
                    using (new System.ServiceModel.OperationContextScope((System.ServiceModel.IContextChannel)channel))
                    {
                        var httpRequestMessageProperty = new System.ServiceModel.Channels.HttpRequestMessageProperty();
                        httpRequestMessageProperty.Headers[TestHeaderName] = TestHeaderValue;
                        System.ServiceModel.OperationContext.Current.OutgoingMessageProperties.Add(System.ServiceModel.Channels.HttpRequestMessageProperty.Name, httpRequestMessageProperty);
                        resultTask = channel.GetHeaderAsync(TestHeaderName, initialYield);
                    }

                    var headerValue = await resultTask;
                    Assert.Equal(TestHeaderValue, headerValue);
                }
                finally
                {
                    ServiceHelper.CloseServiceModelObjects((System.ServiceModel.Channels.IChannel)channel, factory);
                }
            }
        }
Beispiel #2
0
        // should be checked
        public string GetIP()
        {
            OperationContext context = OperationContext.Current;

            System.ServiceModel.Channels.MessageProperties             properties = context.IncomingMessageProperties;
            System.ServiceModel.Channels.RemoteEndpointMessageProperty endpoint   = properties[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty;

            string address = string.Empty;

            if (properties.Keys.Contains(System.ServiceModel.Channels.HttpRequestMessageProperty.Name))
            {
                System.ServiceModel.Channels.HttpRequestMessageProperty endpointLoadBalancer = properties[System.ServiceModel.Channels.HttpRequestMessageProperty.Name] as System.ServiceModel.Channels.HttpRequestMessageProperty;
                if (endpointLoadBalancer != null && endpointLoadBalancer.Headers["X-Forwarded-For"] != null)
                {
                    address = endpointLoadBalancer.Headers["X-Forwarded-For"];
                }
            }

            if (string.IsNullOrEmpty(address))
            {
                address = endpoint.Address;
            }

            return(address);
        }
Beispiel #3
0
        public void PolaczBIRpub()
        {
            //Create the binding.
            var myBinding = new WSHttpBinding(SecurityMode.Transport);

            myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            myBinding.MessageEncoding = WSMessageEncoding.Mtom;

            var ea     = new EndpointAddress("https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc"); //test
            var client = new UslugaBIRzewnPublClient(myBinding, ea);

            client.Open();

            //logowanie bez sida
            string sid = client.Zaloguj("123456789");

            using (new OperationContextScope(client.InnerChannel))
            {
                var requestMessage = new System.ServiceModel.Channels.HttpRequestMessageProperty();
                requestMessage.Headers["sid"] = sid;
                OperationContext.Current.OutgoingMessageProperties[System.ServiceModel.Channels.HttpRequestMessageProperty.Name] = requestMessage;

                var paramGR1 = new UslugaBIRzewnPublClient();
            }
//'DANE SZUKAJ 1
//Dim objParametryGR1 As New UslugaBIRpubl.ParametryWyszukiwania
//objParametryGR1.Nip = "1111111111"
//txtResult.Text &= "### DaneSzukaj (grupa 1):" & vbCrLf &
//cc.DaneSzukaj(objParametryGR1) & vbCrLf & vbCrLf
//''DANE POBIERZ PEŁNY RAPORT
//txtResult.Text &= "### DanePobierzPelnyRaport:" & vbCrLf &
//cc.DanePobierzPelnyRaport("39002176400000", "PublDaneRaportPrawna", "") & vbCrLf &
//vbCrLf
//'WYLOGUJ
//txtResult.Text &= "### Wyloguj:" & vbCrLf & cc.Wyloguj(strSID) & vbCrLf &
//vbCrLf
//'GET VALUE
//txtResult.Text &= "### GetValue(KomunikatKod):" & vbCrLf &
//cc.GetValue("KomunikatKod") & vbCrLf
//txtResult.Text &= "### GetValue(KomunikatTresc):" & vbCrLf &
//cc.GetValue("KomunikatTresc") & vbCrLf
//txtResult.Text &= "### GetValue(StatusSesji):" & vbCrLf &
//cc.GetValue("StatusSesji") & vbCrLf
//End Using
//cc.Close()
//End Sub
        }
Beispiel #4
0
 /// <summary>
 /// Set correlation activity id in the header of request.
 /// </summary>
 /// <param name="activityId">The correlation activity identifier to set in the header.</param>
 private void SetActivityIdInHttpHeader(Guid activityId)
 {
     System.ServiceModel.Channels.HttpRequestMessageProperty httpHeaders = new System.ServiceModel.Channels.HttpRequestMessageProperty();
     httpHeaders.Headers[HttpCorrelationActivityIDHeader] = activityId.ToString();
     OperationContext.Current.OutgoingMessageProperties[System.ServiceModel.Channels.HttpRequestMessageProperty.Name] = httpHeaders;
 }