当前位置: 首页>>代码示例>>C#>>正文


C# Channels.HttpRequestMessageProperty类代码示例

本文整理汇总了C#中System.ServiceModel.Channels.HttpRequestMessageProperty的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestMessageProperty类的具体用法?C# HttpRequestMessageProperty怎么用?C# HttpRequestMessageProperty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpRequestMessageProperty类属于System.ServiceModel.Channels命名空间,在下文中一共展示了HttpRequestMessageProperty类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BeforeSendRequest

 public object BeforeSendRequest(ref Message request, IClientChannel channel)
 {
     HttpRequestMessageProperty property = new HttpRequestMessageProperty();
       property.Headers.Add("username", HttpContext.Current.User.Identity.Name);
       request.Properties.Add("username", property);
       return null;
 }
开发者ID:asdlvs,项目名称:MinStat,代码行数:7,代码来源:IdentityInspector.cs

示例2: Apply

		internal void Apply (HttpRequestMessageProperty hp)
		{
			foreach (var key in Headers.AllKeys)
				hp.Headers [key] = Headers [key];
			if (Accept != null)
				hp.Headers ["Accept"] = Accept;
			if (ContentLength > 0)
				hp.Headers ["Content-Length"] = ContentLength.ToString (NumberFormatInfo.InvariantInfo);
			if (ContentType != null)
				hp.Headers ["Content-Type"] = ContentType;
			if (IfMatch != null)
				hp.Headers ["If-Match"] = IfMatch;
			if (IfModifiedSince != null)
				hp.Headers ["If-Modified-Since"] = IfModifiedSince;
			if (IfNoneMatch != null)
				hp.Headers ["If-None-Match"] = IfNoneMatch;
			if (IfUnmodifiedSince != null)
				hp.Headers ["If-Unmodified-Since"] = IfUnmodifiedSince;
			if (Method != null)
				hp.Method = Method;
			if (SuppressEntityBody)
				hp.SuppressEntityBody = true;
			if (UserAgent != null)
				hp.Headers ["User-Agent"] = UserAgent;
		}
开发者ID:nickchal,项目名称:pash,代码行数:25,代码来源:OutgoingWebRequestContext.cs

示例3: BeforeSendRequest

		public object BeforeSendRequest(ref Message request, IClientChannel channel)
		{
			var tokenInjector = ServiceLocator.Current.GetInstance<ISecurityTokenInjector>();

			if (tokenInjector != null)
			{
				object httpRequestMessageObject;

				if (request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out httpRequestMessageObject))
				{
					var httpRequestMessage = httpRequestMessageObject as HttpRequestMessageProperty;

					if (httpRequestMessage != null)
						tokenInjector.InjectToken(httpRequestMessage.Headers);
				}
				else
				{
					var httpRequestMessage = new HttpRequestMessageProperty();
					tokenInjector.InjectToken(httpRequestMessage.Headers);
					request.Properties.Add(HttpRequestMessageProperty.Name, httpRequestMessage);
				}
			}

			return null;
		}
开发者ID:gitter-badger,项目名称:vc-community-1.x,代码行数:25,代码来源:SecurityTokenEndpointBehavior.cs

示例4: QueryString_Property_Sets

 public static void QueryString_Property_Sets()
 {
     const string newQueryString = "name=Mary";
     HttpRequestMessageProperty requestMsgProperty = new HttpRequestMessageProperty();
     requestMsgProperty.QueryString = newQueryString;
     Assert.Equal<string>(newQueryString, requestMsgProperty.QueryString);
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:wcf,代码行数:7,代码来源:HttpRequestMessagePropertyTest.cs

示例5: Main

        static void Main(string[] args)
        {
            var aosUriString = ClientConfiguration.Default.UriString;

            var oauthHeader = OAuthHelper.GetAuthenticationHeader();
            var serviceUriString = SoapUtility.SoapHelper.GetSoapServiceUriString(UserSessionServiceName, aosUriString);

            var endpointAddress = new System.ServiceModel.EndpointAddress(serviceUriString);
            var binding = SoapUtility.SoapHelper.GetBinding();

            var client = new UserSessionServiceClient(binding, endpointAddress);
            var channel = client.InnerChannel;

            UserSessionInfo sessionInfo = null;

            using (OperationContextScope operationContextScope = new OperationContextScope(channel))
            {
                HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
                 requestMessage.Headers[OAuthHelper.OAuthHeader] = oauthHeader;
                 OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
                 sessionInfo = ((UserSessionService)channel).GetUserSessionInfo(new GetUserSessionInfo()).result;
            }

            Console.WriteLine();
            Console.WriteLine("User ID: {0}", sessionInfo.UserId);
            Console.WriteLine("Is Admin: {0}", sessionInfo.IsSysAdmin);
            Console.ReadLine();
        }
开发者ID:pvillads,项目名称:Dynamics-AX-Integration,代码行数:28,代码来源:Program.cs

示例6: Main

        public static void Main()
        {
            // Typically this request would be constructed by a web browser or non-WCF application instead of using WCF

            Console.WriteLine("Starting client with ByteStreamHttpBinding");

            using (ChannelFactory<IHttpHandler> cf = new ChannelFactory<IHttpHandler>("byteStreamHttpBinding"))
            {
                IHttpHandler channel = cf.CreateChannel();
                Console.WriteLine("Client channel created");

                Message byteStream = Message.CreateMessage(MessageVersion.None, "*", new ByteStreamBodyWriter(TestFileName));
                HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
                httpRequestProperty.Headers.Add("Content-Type", "application/octet-stream");
                byteStream.Properties.Add(HttpRequestMessageProperty.Name, httpRequestProperty);

                Console.WriteLine("Client calling service");
                Message reply = channel.ProcessRequest(byteStream);

                //Get bytes from the reply 
                XmlDictionaryReader reader = reply.GetReaderAtBodyContents();
                reader.MoveToElement();
                String name = reader.Name;
                Console.WriteLine("First element in the byteStream message is : <" + name + ">");
                byte[] array = reader.ReadElementContentAsBase64();
                String replyMessage = System.Text.Encoding.UTF8.GetString(array);
                Console.WriteLine("Client received a reply from service of length :" + replyMessage.Length);
            }

            Console.WriteLine("Done");
            Console.WriteLine("Press <ENTER> to exit client");
            Console.ReadLine();
        }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:33,代码来源:Client.cs

示例7: Method_Property_Sets

 public static void Method_Property_Sets()
 {
     const string newMethod = "PUT";
     HttpRequestMessageProperty requestMsgProperty = new HttpRequestMessageProperty();
     requestMsgProperty.Method = newMethod;
     Assert.Equal<string>(newMethod, requestMsgProperty.Method);
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:wcf,代码行数:7,代码来源:HttpRequestMessagePropertyTest.cs

示例8: CreateNormalRequestMessage

 private static Message CreateNormalRequestMessage()
 {
     var requestProperty = new HttpRequestMessageProperty();
      Message requestMessage = Message.CreateMessage(MessageVersion.None, null);
      requestMessage.Properties.Add(HttpRequestMessageProperty.Name, requestProperty);
      return requestMessage;
 }
开发者ID:kalkie,项目名称:BasicAuthenticationUsingWCFRest,代码行数:7,代码来源:HttpRequestAuthorizationExtractorTest.cs

示例9: BeforeSendRequest

 public object BeforeSendRequest(ref System.ServiceModel.Channels.Message Request,
     System.ServiceModel.IClientChannel Channel)
     {
     HttpRequestMessageProperty httpRequestMessage;
     object httpRequestMessageObject;
     if (Request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out httpRequestMessageObject))
         {
         httpRequestMessage = httpRequestMessageObject as HttpRequestMessageProperty;
         if (String.IsNullOrEmpty(httpRequestMessage.Headers["WPMediaToken"]))
             {
             if (WMB.WPMediaApplicationState.Instance.Properties.ContainsKey("WPMediaToken"))
                 httpRequestMessage.Headers["WPMediaToken"] = WMB.WPMediaApplicationState.Instance.Properties["WPMediaToken"].ToString();
             }
         }
     else
         {
         if (WMB.WPMediaApplicationState.Instance.Properties.ContainsKey("WPMediaToken"))
             {
             httpRequestMessage = new HttpRequestMessageProperty();
             httpRequestMessage.Headers.Add("WPMediaToken",
                 WMB.WPMediaApplicationState.Instance.Properties["WPMediaToken"].ToString());
             Request.Properties.Add(HttpRequestMessageProperty.Name, httpRequestMessage);
             }
         }
     return null;
     }
开发者ID:heinzsack,项目名称:DEV,代码行数:26,代码来源:HeaderInsertClientMessageInspector.cs

示例10: Main

        static void Main(string[] args)
        {
            var binding = new WSHttpBinding(SecurityMode.Transport);
            binding.Name = "binding";
            binding.MaxReceivedMessageSize = 500000;
            binding.AllowCookies = true;

            var client = new SyncReplyClient(binding, new EndpointAddress("https://platform.gaelenlighten.com/api/soap12"));

            using (new OperationContextScope(client.InnerChannel))
            {
                var requestMessage = new HttpRequestMessageProperty();
                requestMessage.Headers["Tenant"] = "tenant.gaelenlighten.com"; // Add your tenant
                var token = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes("username:password")); // Add your username and password here
                requestMessage.Headers["Authorization"] = token;
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;

                var response = client.GetReports(new GetReports
                {
                    //// Specify filters
                    ReportStatus = ReportStatus.New,
                    Take = 100,
                    Skip = 0
                });

                var reportList = response.Reports;
                foreach (var report in reportList)
                {
                    ////Example of iterating through the report list
                }
                response.PrintDump();

                Console.ReadLine();
            }
        }
开发者ID:gael-ltd,项目名称:gaelenlighten-platform-samples,代码行数:35,代码来源:Program.cs

示例11: BeforeSendRequest

 public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
 {
     HttpRequestMessageProperty httpRequestMessage;
     object httpRequestMessageObject;
     if (request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out httpRequestMessageObject))
     {
         httpRequestMessage = httpRequestMessageObject as HttpRequestMessageProperty;
         if (string.IsNullOrEmpty(httpRequestMessage.Headers[HttpRequestHeader.Authorization]))
         {
             var authResult = Expenses.WPF.AADSignIn.AADAuthResult;
             if (authResult != null)
             {
                 httpRequestMessage.Headers[HttpRequestHeader.Authorization] = Expenses.WPF.AADSignIn.AADAuthResult.CreateAuthorizationHeader();
             }
         }
     }
     else
     {
         var authResult = Expenses.WPF.AADSignIn.AADAuthResult;
         if (authResult != null)
         {
             httpRequestMessage = new HttpRequestMessageProperty();
             httpRequestMessage.Headers.Add(HttpRequestHeader.Authorization, Expenses.WPF.AADSignIn.AADAuthResult.CreateAuthorizationHeader());
             request.Properties.Add(HttpRequestMessageProperty.Name, httpRequestMessage);
         }
     }
     return null;
 }
开发者ID:write2sushma,项目名称:CloudEnabledApps,代码行数:28,代码来源:ExpensesClientMessageInspector.cs

示例12: IncomingWebRequestContext

		internal IncomingWebRequestContext (OperationContext context)
		{
			if (context.IncomingMessageProperties != null)
				hp = (HttpRequestMessageProperty) context.IncomingMessageProperties [HttpRequestMessageProperty.Name];
			else
				hp = new HttpRequestMessageProperty ();
		}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:IncomingWebRequestContext.cs

示例13: BeforeSendRequest

 public object BeforeSendRequest(ref Message request, IClientChannel channel)
 {
     object httpRequestMessageObject;
     if (request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out httpRequestMessageObject))
     {
         HttpRequestMessageProperty httpRequestMessage = httpRequestMessageObject as HttpRequestMessageProperty;
         if (httpRequestMessage != null)
         {
             httpRequestMessage.Headers[SERVICE_KEY_HTTP_HEADER] = (ServiceKey ?? string.Empty);
         }
         else
         {
             httpRequestMessage = new HttpRequestMessageProperty();
             httpRequestMessage.Headers.Add(SERVICE_KEY_HTTP_HEADER, (ServiceKey ?? string.Empty));
             request.Properties[HttpRequestMessageProperty.Name] = httpRequestMessage;
         }
     }
     else
     {
         HttpRequestMessageProperty httpRequestMessage = new HttpRequestMessageProperty();
         httpRequestMessage.Headers.Add(SERVICE_KEY_HTTP_HEADER, (ServiceKey ?? string.Empty));
         request.Properties.Add(HttpRequestMessageProperty.Name, httpRequestMessage);
     }
     return null;
 }
开发者ID:pouc,项目名称:qv-extensions,代码行数:25,代码来源:ServiceKeyClientMessageInspector.cs

示例14: BeforeSendRequest

        /// <summary>
        /// Enables inspection or modification of a message before a request message is sent to a service.
        /// </summary>
        /// <returns>
        /// The object that is returned as the <paramref name="correlationState "/>argument of the <see cref="M:System.ServiceModel.Dispatcher.IClientMessageInspector.AfterReceiveReply([email protected],System.Object)"/> method. This is null if no correlation state is used.The best practice is to make this a <see cref="T:System.Guid"/> to ensure that no two <paramref name="correlationState"/> objects are the same.
        /// </returns>
        /// <param name="request">The message to be sent to the service.</param><param name="channel">The WCF client object channel.</param>
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            HttpRequestMessageProperty httpRequest;
            if (request.Properties.ContainsKey(HttpRequestMessageProperty.Name))
            {
                httpRequest = request.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
            }
            else
            {
                httpRequest = new HttpRequestMessageProperty();
                request.Properties.Add(HttpRequestMessageProperty.Name, httpRequest);
            }
            if (httpRequest != null)
            {
                httpRequest.Headers.Add("Authorization", string.Format("{0}", AdalTokenManager.GetToken(serviceName).CreateAuthorizationHeader()));
                var supportCode = "";
                RuntimeFactory.Current.GetStateStorageContainer().TryGetItem("supportCode", out supportCode);
                var meta = new RequestHeader
                             {
                                 Environment = Utilities.GetEnvironment(),
                                 ConfigSet = Utilities.GetConfigSetName(),
                                 ServiceName = RuntimeFactory.Current.ServiceName,
                                 MessageId = Guid.NewGuid().ToString(),
                                 ServerIdentity = Environment.MachineName,
                                 RuntimeInstance = RuntimeFactory.Current.InstanceId.ToString(),
                                 SupportCode = supportCode
                             };
                httpRequest.Headers.Add("X-Stardust-Meta", Convert.ToBase64String(JsonConvert.SerializeObject(meta).GetByteArray()));
            }

            return RuntimeFactory.Current;

        }
开发者ID:JonasSyrstad,项目名称:Stardust,代码行数:40,代码来源:AdalWcfClientInspector.cs

示例15: Button1_Click

        protected async void Button1_Click(object sender, EventArgs e)
        {
            var authServer = new AuthorizationServerDescription()
            {
                
                TokenEndpoint = new Uri("http://localhost:53022/OAuth/token "),
                ProtocolVersion = ProtocolVersion.V20
            };
            WebServerClient Client= new WebServerClient(authServer, "idefav", "1");

            var code =await Client.GetClientAccessTokenAsync(new string[] { "http://localhost:55045/IService1/DoWork" });
            string token = code.AccessToken;
            Service1Reference.Service1Client service1Client=new Service1Client();
            var httpRequest = (HttpWebRequest)WebRequest.Create(service1Client.Endpoint.Address.Uri);
            ClientBase.AuthorizeRequest(httpRequest,token);
            var httpDetails = new HttpRequestMessageProperty();
            httpDetails.Headers[HttpRequestHeader.Authorization] = httpRequest.Headers[HttpRequestHeader.Authorization];
            
            using (var scope = new OperationContextScope(service1Client.InnerChannel))
            {
                
                if (OperationContext.Current.OutgoingMessageProperties.ContainsKey(HttpRequestMessageProperty.Name))
                {
                    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpDetails;
                }
                else
                {
                    OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, httpDetails);
                }
                
                Button1.Text= service1Client.DoWork();
            }


        }
开发者ID:idefav,项目名称:IdefavOAuth2Demo,代码行数:35,代码来源:Default.aspx.cs


注:本文中的System.ServiceModel.Channels.HttpRequestMessageProperty类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。