We have a asmx web service that are used by hundreds of customers. We recently did some refactoring including an upgrade to .NET 4.0.
We tested the refactored version by doing a lot of request using data from our logs as parameters and compared the raw result of the old and refactored web service. The only difference we found was that the namespace of the result was in another order. Note that old and refactored web service were on different servers. Different order of the namespace seems safe to release so that was what we did...
Today I was contacted by a customer telling me that they were unable to read our result and pointing this namespace issue as the reason. This seems very strange to me since they must have a more or less corrupt XML parser to get an issue like this. I would however try to isolate this, since we loose a lot of money every hour.
I reverted our project back to .NET 3.5 but get the same namespace order. But there seems to be a difference of the namespace order between the servers.
Does anyone know why the order is different? Does it have to do with .NET version, version of other components or is it just random?
From server one:
<?xml version="1.0" encoding="utf-8"?>
<result xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://mydomain.com/">
...
From server two:
<?xml version="1.0" encoding="utf-8"?>
<result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://mydomain.com/">
...
I'm a bit stuck...
Related
I am not expert of Internet communication protocols. Normally I develop some WebServices in c#, for my needs. My functions are developed with the [WebMethod] keyword and return numbers, for example two coordinates.
To call the WebService, for example with a browser, I write:
https://www.mysite.xx/MyWebService.asmx/MyWebMethod?Request=..Parameters ...
And I get an answer like:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">-102866,667000005;-92718,2779999226</string>
Till to day, calling the WebService with programs, I process the above answer, to get what I need, i.e. just the two numbers. I would like to know whether it is possible to simply get an answer with the two numbers only, without the other stuff.
First off a little context, I work for a channel manager company that builds custom endpoints for their clients to talk to. We currently mostly code in c#.
This is the first time we are connecting with a client that asked us to support a soap web service.
Sadly, we don't have previous experience in this and I can't find any concrete explanations to what it looks like to support a SOAP call.
Currently, it looks like that I have to simply use text processing methods to run through the received XML and parse it in a non-generic way.
But this feels like there should be a more straightforward approach since the protocol is almost 20 years old.
For almost every search result I only get examples of what the XML looks like, but what I'm interested in, is what I need to implement in my application to host an endpoint for the client to successfully post and receive a SOAP message from. And if there is a way to do this without something like XmlWriters/Readers.
Anything to help me get on my way mary is appreciated!
Greetings, Davey
WCF is the least outdated library for offering SOAP.
When you can define the contracts then you're in luck, that's just writing a C# interface.
But when necessary you can also import WSDL specifications and generate C# from that.
it looks like that I have to simply use text processing methods to run through the received XML and parse it
Don't even consider that. Everything is under control of schemas. And you will also have to generate valid return packages.
I have an old C# .net4 project that needed maintenance recently and one of the unit tests that was comparing a serialized object to a "staple" XML string started failing because of slight namespace differences, i.e. the namespace on the compare string was xmlns:xsd and on the serialized object it was xmlns:xsi.
The weird thing is that the same unit test works fine on a different machine.
I'm rather clueless as to why this could happen.
Change tests. You shold't compare xmls as strings.
<a i="1" b="2"/>
is same as
<a b="2" i="1"/>
if you compare it as strings they will be different, but as xml they are identical.
This post shoud help you.
Don't know if it's your case, but, when I had to make some WCF retrocompatible with ASMX older webservices, it turned out that XmlSerializer works differently based on the version on the .NET framework, causing exceptions when trying to deserialize objects or re-read xml.
It makes sense that an older application, working on an old machine, with an old version of the framework might act differently on the new machine because even if the project targets an older framework, the newer one is used to elaborate some parts, such as the XML.
To add further details, I think the difference was between the passage from the 2.0 .NET framework to the newer ones (3, 3.5 etc). But I'm not sure of this, since quite some time has passed.
I repeat, I don't know if this is your case, but it might be a reason. One test should be to upgrade on the older machine the framework to the same version as the newer machine, and check if produces the same output, then do a system rollback to the previous state just before the installation of the newer framework.
Check this:
this, absolutely THIS, and this.
Let me know if this was useful.
This question already has answers here:
Consuming a REST XML web service
(4 answers)
Read xml from URL
(2 answers)
Closed 8 years ago.
I have a third-party web service that I need to use. The calls to it will be something like this:
https://somesitename.com/Service.dll?[operation]?[parameter1]&[parameter2]
It returns various XML structures depending on the operation called and the results of the operation.
It can be as simple as this:
<?xml version="1.0"?>
<RESULTS>
<VALUE>some return value here</VALUE>
</RESULTS>
Or for a call that returns slightly more complex data, it could be like this:
<?xml version="1.0" ?>
<RESULTS>
<RETURN>
<RESPONSEMSG>Some message.</RESPONSEMSG>
</RETURN>
<DATA>
<COUNT>1</COUNT>
<VALUE1>1</VALUE1>
<VALUE2>1</VALUE2>
<VALUE3>FALSE</VALUE3>
</DATA>
</RESULTS>
If that call had errored instead, it would just return something like:
<?xml version="1.0" ?>
<RESULTS>
<RETURN>
<ERROR>Error Message.</ERROR>
</RETURN>
</RESULTS>
So, basically I'm just trying to consume the XML response from a REST service. There is no data contract for it, and all I have to go on is the example responses that were provided to me. Should I build poco classes for each type of result? I'm thinking that I would use HTTPClient or WebClient to make the requests to the service. Then I'd need to somehow deserialize the resulting XML into an object that I can return. Is there a best practice or pattern for this kind of thing? Any advice would be appreciated, thanks!
lots of technologies
linq2xml
or you can use xpath, there are loads of xml parsing libraries out there.
linq2xml is probably the easiest these days though.
Only problem with linq2xml is if you parse the whole thing in 1 function you really want to validate the xml structure before hand - to find the problems.
Yes POCO is best for this case. Then parse the XML using LINQ-to-XML. Its always good to go for strongly-typed programming
I have never so much as successfully loaded an xml document in WebMatrix (or JavaScript for that matter), despite how many times I have tried.
No online example is complete or accurate.
if I had an xml file that contained this (and only this):
<?xml version="1.0" encoding="utf-8" ?>
<someNode>
<someValue>HEY THERE! I'M XML!</someValue>
<someValueTwo>Another Value</someValueTwo>
</someNode>
How could I (start from loading the xml document etc.) plot the values of the two elements on one of my WebMatrix pages (please include where the code you are providing goes, as I have no clue).
Please include all the places I would need the code not just loading or writing to page.
*******UPDATE:******
Oh, well, nvm, xml is useless anyway, I'll just use another database or render the contents of another external cshtml page or something.
I have looked at XPath before and such, but I am not really worried about selecting them by tagname, id, attribute, etc because researching that would have been easy.
Sometimes I wonder why XML is still around...(Yes, I know it (is supposed to) help communicate data across very different languages and platforms) but the truth is, even with online tutorials and walkthroughs, it doesn't work, and it doesn't seem like there's anyone left who does know how to do this really. Why is it still around? Isn't it time that WebMatrix got rid of the xml based methods, since they don't work, and since there isn't anyone left who knows how to so much as try to load an xml file without getting errors?
Just curious if xml will be faded out in future updates.
*******UPDATE:******
Okay, I'm told that xml is supposed to still be useful. Do you just have to not be me to get it to work, lol?
I've never done anything with WebMatrix so I'm not gonna have much to say on that front. I am however confused by your attitude toward XML. If you mean only that XML is not useable in the WebMatrix context I can neither confirm nor deny that; however XML is dead useful in a plethora of other scenarios, and it is unclear from your question if you know that or not. Sorry I can't help on your question, just clarifying that XML is a very powerful tool as far as data file formats are concerned.