Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Returning XML response before method
Message
 
À
09/12/2016 17:48:40
Information générale
Forum:
ASP.NET
Catégorie:
Web Services
Versions des environnements
Environment:
VB 9.0
OS:
Windows 8.1
Network:
Windows Server 2012
Database:
Visual FoxPro
Application:
Web
Divers
Thread ID:
01644778
Message ID:
01644784
Vues:
36
What are you using for your Web Service? ASMX or WCF?

Both mechanisms support methods you can implement on the service to inject custom data into the document. It's not trivial and you'd have to inspect each response to decide whether you need to actually inject. You can't just put XML at the top of the page (or end) because as you found out that produces invalid XML - the XML has to become part of the XML document. Typically in SOAP this is done with custom SOAP Headers. You can effectively define a custom SOAP Header and then set that header for the requests that need it.

It's been a long while since I looked at this and it's ugly. Really what you should do is add that functionality to the main SOAP envelope and the payload you're sending. A common way to do this is a common Request and Response object structure that includes message specific objects (like hasErrors,errorCode, etc.) which then has a content element into which you push your actual result data. It's a pretty common service pattern that works really well. You basically create a base ResponseMessage object and you can then subclass that to add the custom result properties that you need to actually return to the client. Most enterprise systems use a variation of this message based service style.

+++ Rick ---

>In the main code, in order to bypass the default Xml output that would be served by the Web Service method, I have added this code:
>
>
>Dim loHttpResponse As System.Web.HttpResponse = Nothing
>loHttpResponse = System.Web.HttpContext.Current.Response
>loHttpResponse.Clear()
>loHttpResponse.ClearContent()
>loHttpResponse.ClearHeaders()
>loHttpResponse.ContentType = "text/xml"
>loHttpResponse.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8")
>loHttpResponse.Write(cXml)
>loHttpResponse.End()
>
>
>This takes over the response and sends some data.
>
>But, the client says "Response is not well-formed XML."
>
>If I replace the cXml line with:
>
>
>loHttpResponse.Write("test")
>
>
>...I can see the client reacting and saying that this has to be text/xml content.
>
>So, somethings get sent. But, something is not properly received on the other end.
>
>Anyone would know what is missing?
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform