Thursday 15 March 2012

asp.net - how to modify http header of request; web reference in C# -


I am creating a .NET application that uses a web service. In the request of that web service I need to set the connection port "off" I have been googling for this one day, but is not able to get anything to work.

My best effort is the code below, which attempts to override the GetWebRequest method to add header. It appears to be failing - I keep a breakpoint in it, and when I run my application, breakpoints are never killed and the connection header is not set (I'm evaluating it to see the http headers Rather than behaving

Some information: When I add web references using Visual Studio, then I'm going to the project in Solutions Explorer. It's clicked, "Add Service Reference", "Advanced", then "Add Web Reference".

  Name Location System.Net {Public category MyHttpProtocol: SoapHttpClientProtocol {Protected Override WebRequest GetWebRequest (Uri Uri) {HttpWebRequest webRequest = (HttpWebRequest) base.GetWebRequest (URI); WebRequest.Headers.Add ("connection", "off"); return webRequest;}}}    < P> 

You are creating this as a request to use a IClientMessageInspector . Very similar And you have this question Education should respond.

In WCF many things are involved in making behavior and overriding some aspects of the process specified in web config, which can be a bit nuanced but very powerful. You can add your request to edit your comment.

Look at your code like this?

  PublicSearchForSendRequest (Reference System.ServiceModel.Channels.Message does request, System.ServiceModel.IClientChannel channel) {var httpRequestMessage = new HttpRequestMessageProperty (); HttpRequestMessage.Headers.Add ("Connection", "Closed"); request. Properties Add (http.pndseasapapaprotti.Name, httpRequestMessage); Return tap; }    

No comments:

Post a Comment