1

I am dealing with a web service from one of my government agencies for electronic documents. The WSDL can be found here: https://maullin.sii.cl/DTEWS/CrSeed.jws?WSDL

I tried calling the getSeed() method (which is the only relevant one) at http://www.soapclient.com/soaptest.html to see if it's working, and indeed it is.

I created a WCF Service Library to test this and i got the following error:

System.ServiceModel.FaultException: 'org.xml.sax.SAXParseException: Content is not allowed in prolog.'

A quick online search shows that many users have this problem trying to implement this particular Web service and they all seems to point out some windows update. Everyone points to a different one to uninstall and that's how some of them resolved this issue.

I don't believe it's a matter of a particular windows update, perhaps there is something else. So instead I tried creating the WCF Service Application and hosting the web service in IIS to check if maybe it was some debug problem.

In a console project I try to call the getSeed() method, but it ended up returning a null string instead of throwing a SAXParseException.

So whats the deal in here?. It seems pretty straight forward to me:

 1. Add the service reference
 2. Create a new instance of CrSeedClient class
 3. Call getSeed() method.

Why I am getting all this trouble over this particular web service?

BTW, i am using Net Framework 4.7.2 / Windows 10 / Visual Studio 2017

Can anyone test it out please? Thanks.


EDIT !: Read my own answer...

ffenix
  • 543
  • 1
  • 5
  • 22
  • check that nothing precedes the – Mitch Wheat Nov 02 '18 at 01:20
  • I checked in a hex editor and no, no preceding whitespaces or any kind of character before the XML declaration. Also thats why i checked with soaptest website, so i can be sure its not a parser thing... – ffenix Nov 02 '18 at 01:27
  • have you tried testing the web service using soap ui or similar? If it works in the API tool but you code implementation breaks it will let you focus your investigation. If the web method is returning null probably not much you can do.. – JKerny Nov 02 '18 at 05:02
  • I tried testing on http://www.soapclient.com/soaptest.html and the response seems fine. I even tried to use old web service reference (pre net framework 2.0) and still the same error. I am lost on this, it seems like the XML parser is finding an error in the response?. But at the same time other implementations like the one used on soaptest.html seems to parse it just fine... – ffenix Nov 02 '18 at 06:13
  • it is strange that I found that the request was repsonding by grabbing the request in Fiddler. There may be a problem with the response data being deserialized, causing the client to return null by adding a service reference. I suggest you check how does the datacontract defined. – Abraham Qian Nov 02 '18 at 10:32
  • I added an edit, if anyone can see it please... thanks ! – ffenix Nov 03 '18 at 00:37

2 Answers2

1

Ok so in the end this was a nightmare. It involved first disable a security patch made by microsoft. Here the details:

https://support.microsoft.com/en-us/help/3155464/ms16-065-description-of-the-tls-ssl-protocol-information-disclosure-vu

I made it programmatically:

    AppContext.SetSwitch("TestSwitch.LocalAppContext.DisableCaching", true); 
    AppContext.SetSwitch("Switch.System.Net.DontEnableSchSendAuxRecord", true);

That way i could get past the org.xml.sax.SAXParseException which was a response made by the WebServer. Even when i changed the raw message using a custom message enconder, it seems to be WCF or maybe even the OS was writting some bytes or modify the final SOAP message on the fly. Disabling that security patch on the fly prevented this from happening.

Now next thanks to the custom message encoder, i could see that the webservice was finally returning a valid message, but WCF didnt parse it correctly. After hours of testing, i figure it out:

Original response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getSeedResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<getSeedReturn xsi:type="xsd:string">
<?xml version="1.0" encoding="UTF-8"?><SII:RESPUESTA xmlns:SII="http://www.sii.cl/XMLSchema"><SII:RESP_BODY><SEMILLA>013052590000</SEMILLA></SII:RESP_BODY><SII:RESP_HDR><ESTADO>00</ESTADO></SII:RESP_HDR></SII:RESPUESTA>
</getSeedReturn>
</getSeedResponse>
</soapenv:Body>
</soapenv:Envelope>

By removing the ns1 prefix everywhere (including xmlns:ns1="http://DefaultNamespace") i could finally get the correct parsing.

After fixed:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getSeedResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<getSeedReturn xsi:type="xsd:string">
<?xml version="1.0" encoding="UTF-8"?><SII:RESPUESTA xmlns:SII="http://www.sii.cl/XMLSchema"><SII:RESP_BODY><SEMILLA>013052590000</SEMILLA></SII:RESP_BODY><SII:RESP_HDR><ESTADO>00</ESTADO></SII:RESP_HDR></SII:RESPUESTA>
</getSeedReturn>
</getSeedResponse>
</soapenv:Body>
</soapenv:Envelope>

I still dont understand neither the security patch or why WCF fails to parse the message with the NS1 prefix.

If anyone dare to take a look at this i would be very happy, cause i think this solutions are a little hacky and honestly i can see why people would prefer to use java instead of WCF.

sports
  • 7,851
  • 14
  • 72
  • 129
ffenix
  • 543
  • 1
  • 5
  • 22
  • I don't get it. Your "before" and your "after" are exactly the same..... – sports Mar 25 '19 at 19:36
  • Oh yeah, my bad, the before had the string: "ns1" as a prefix. Example: "ns1:getSeedResponse." Removing the ns1 string in the custom enconder fixed all the issues plus disabling the security patch. But in the end (months after) i just abandoned WFC and did the request using WebClient UploadString request. Way easier than all of this pain. – ffenix Mar 25 '19 at 23:01
0

In your scenario (.net 4.7) I prefer to use this technology: "add web reference" and not "add service reference"

Here you can find the difference between using one or another technology, one is more current than the other: Web Reference vs. Service Reference

Since your scenario is not .net core then you have a choice.

sergiokml
  • 41
  • 6
  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 29 '22 at 23:03