Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

.NET Webservice replace tags with < >

Posted on 2004-11-04
19
Medium Priority
?
638 Views
Last Modified: 2008-02-01
I'm trying to use someone's web service that takes a string parameter UserIDs (all wsdl so far) But UserIDs is is really a mini xml in itself <users><user>A</user><user>b</user></users>. I made a string like that and sent thru web service and it returned failure. I did a trace on it and found out .NET webservice changes all the tags < and > to &lt; and &gt;

Is there anyway to preserve < and > as they are without having to modify the web reference into a complex type mannually?
0
Comment
Question by:gotdough
  • 7
  • 5
  • 5
  • +1
18 Comments
 
LVL 2

Expert Comment

by:diablocute
ID: 12500097
You can turn URL Encoding off
0
 
LVL 16

Expert Comment

by:OliWarner
ID: 12501126
If you dont want something converted dont pass it into the replacer...

Otherwise make your own service to replace a custom tag like []s or something like that with <>s after the above has finished...
0
 

Author Comment

by:gotdough
ID: 12501649
Hmm I never heard of url encoding option or replacer under soap. It seems to me I import web reference and I call the functions specified by wsdl.

my code is basically
Dim MyService = new XYZWebService
userList = "<users><user>A</user><user>b</user></users>"
MyService.SendUsers(userList)

Whoever makes it work for me is greatly appreciated
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 16

Expert Comment

by:OliWarner
ID: 12501723
assuming the funtion retuns instead of response outputting:

dim MyService as XYZWebService = new XYZWebService
dim userList as String = "<users><user>A</user><user>b</user></users>"
dim outList as String = MyService.SendUsers(userList)

Damnit I hate VB.net Give me classic ASP or C# anyday...
0
 
LVL 16

Expert Comment

by:OliWarner
ID: 12501729
and then:
Response.Write(outList)
0
 
LVL 16

Expert Comment

by:OliWarner
ID: 12501745
scrub that post... here we go...

dim MyService as XYZWebService = new XYZWebService
dim userList as String = "<users><user>A</user><user>b</user></users>"
dim outList as String = MyService.SendUsers(userList)

outList  = Replace(outList, "&lt;users&gt;", "<users>")
outList  = Replace(outList, "&lt;user&gt;", "<user>")
outList  = Replace(outList, "&lt;/users&gt;", "</users>")
outList  = Replace(outList, "&lt;/user&gt;", "</user>")

Response.Write(outList)
0
 

Author Comment

by:gotdough
ID: 12501779
I think there is a misconception here and I apologize for it. This is not ASP so there is no response object. I'm only writing the client connectivity as a windows application. And feel free to use C# :)

I guess this code is more intuitive

Sub Form_Load handles Form1.OnLoad()
  Dim MyService = new XYZWebService
  XYZWebService.URL = "http://www.xyz.com/getdough.asmx"
  userList = "<users><user>A</user><user>b</user></users>"
  'This line returns fail because server could not interpret &lt;users&gt;&lt;user...
  MsgBox MyService.SendUsers(userList)
End Sub


0
 

Author Comment

by:gotdough
ID: 12501784
Okay again I think what I'm trying to do is not send any &lt; and &gt; out in the first place. I don't care about formatting the response I get back as long as it doesn't generate an error.
0
 
LVL 16

Expert Comment

by:OliWarner
ID: 12501850
Oh I think I see what's going on here...
Any & sysbmols invalidate XML... Its hard to guess not knowing what this mystery service actually does...

http://www.xyz.com/getdough.asmx
Sub Form_Load handles Form1.OnLoad()
  Dim MyService = new XYZWebService
  XYZWebService.URL = "http://www.xyz.com/getdough.asmx"
  userList = "<users><user>A</user><user>b</user></users>"
  MsgBox MyService.SendUsers(Replace(Replace(userList ,"&lt;","<"),"&gt;",">"))
End Sub

That's pretty fugly...

If that still doesnt work you've got something URLEncoding your urls automatically which needs to be turned off.
Either that or you need to modify this webservice to swap &lt; and &gt; back to proper characters...

I apologise or so many bodged attempts but its 6:50am here and I'm still yet to get some sleepage...
0
 

Author Comment

by:gotdough
ID: 12502080
Let's not get too far off, all I'm trying to figure out is

I'm trying to send:
MyService.SendUsers("<users><user>A</user><user>b</user></users>")

Trace shows
<SendUsers>
<UserList>&lt;users&gt;&lt;user&gt;A&lt;/user&gt;&lt;user&gt;&lt;/user&gt;&lt;/users&gt;</UserList>
</Sendusers>

I want the trace to show
<SendUsers>
<UserList><users><user>A</user><user>b</user></users><UserList>
</Sendusers>

Without having to modify anything on the webservice end or web reference
0
 
LVL 2

Expert Comment

by:diablocute
ID: 12504421
I don't know what MyService is a type of

but HttpRequest does have a property for URL Encoding

HttpRequest.ContentType = "application/x-www-form-urlencoded";
or "text/html"

Try to find the one you are looking for.

The problem you are having is called URL Encoding
0
 
LVL 2

Expert Comment

by:diablocute
ID: 12504468
sorry, didn't read that it was a webservice

There is a property called myService.RequestEncoding
0
 
LVL 2

Expert Comment

by:diablocute
ID: 12508282
OliWarner: I really dislike when people post links that they google and it's the first one they see, without ever reading how relavent it is to the question

Back to the typic

gotdough, I think you should try this

myService.RequestEncoding = "text/xml";

Based on that, myService object will take the input as text and pass it on.
0
 
LVL 16

Expert Comment

by:OliWarner
ID: 12508452
diablocute that's the MSDN page on services using RequestEncoding.
Its explains how to use it in different languages and what the returns will be.

Yout assumptions on whether it will work are based on the webservice actually inheriting the command from the WebClientProtocol class as the page I posted explains. If it doesnt do that its a rubbished suggestion.

I really dislike when people care more about the points that fixing an issue. Chill down, I'm only explaining things.
0
 
LVL 2

Expert Comment

by:diablocute
ID: 12508706
I did some more research,

"text/html" might work also
0
 

Author Comment

by:gotdough
ID: 12509381
Thanks for the suggest guys. Unfortunately RequestEncoding is some enumerate type and I think it only specify the character encoding while this problem is with XML serialization. I just figure out this encoding is called ISO 8859-1 that changes HTML/XML characters into ampersand symbols.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12857498
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question