Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sending headers to a Web Service
Message
De
28/08/2012 16:37:36
 
 
À
28/08/2012 11:38:54
Information générale
Forum:
ASP.NET
Catégorie:
Web Services
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01551683
Message ID:
01551746
Vues:
42
I proceeded more on this. Their certificate is valid and I was able to move pass that marker. Their WS is now validating the method parameter, the XML, that we are sending. But, in order to reach that part, I had to go right into the Reference.vb file, the auto generated one once the reference has been added into the project, and add something like this:
        Protected Overrides Function GetWebRequest(uri As Uri) As System.Net.WebRequest
            Dim request As System.Net.HttpWebRequest = DirectCast(MyBase.GetWebRequest(uri), System.Net.HttpWebRequest)
            request.Headers("certificate") = "Certificate here"
            Return request
        End Function

        Protected Overrides Function GetWebResponse(request As System.Net.WebRequest) As System.Net.WebResponse
            Dim response As System.Net.HttpWebResponse = DirectCast(MyBase.GetWebResponse(request), System.Net.HttpWebResponse)

            Dim loXmlDocument As System.Xml.XmlDocument = New System.Xml.XmlDocument
            loXmlDocument.Load(response.GetResponseStream())
            'loXmlDocument.OuterXml

            Return response
        End Function
So, as you can see, I am overriding the request and response behavior of the Web Service. One to add a certificate and one to intercept the full envelope of the SOAP object returned.

The GetWebRequest() method overrides and allow to add support to adding headers to a high level Web Service object I have in reference in the the project. As, natively, this is not supported as is, I have to proceed like that.

But, this is not a good approach. I only did this to test that the certificate is valid and that I was able to get a correct answer from their Web Service to validate the XML received as a parameter. I do not want to this change to be permanent as this is part of a pre-generated file when I added a reference to that Web Service in my project.

I will see about using a Service instead of a Web Reference. Maybe that will help. I will also go with low level SOAP access and see if I can get better support.

The goal is to avoid modifying the pre-generated file as this is not the right way to do it. I also do not want to have to insert something in there every time we update the Web Reference. Try to explain that to a new developer about what behavior is caused by what when the proxy has been adjusted. The proxy should remain as is.

In the mean time, if you think about something else, feel free to share some ideas. I provided an up to date status and about a small limitation in .NET which forces me to do it like that presently.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform