Send XML via HTTPS.

maniekbmaniekb Member Posts: 15
edited 2012-04-05 in NAV Three Tier
Hello,

Someone of you wizards could help me? Of course, previously search mibuso for answer.
I'm trying send xml file via https. Xml file is available at http://www.e-deklaracje.gov.pl/files/dopobrania/eDek_Specyfikacja_We-Wy_1.4.2_Test.pdf on pages 23/38 and 24/38. Given method is useful when we do not have a certificate to sign documents, and therefore added to the end of the file is a node: <podp:DaneAutoryzujace...'>. Then the whole xml file must be encoded by base64 as it is shown in the above mentioned documentation (pages 29/38).
So my send.xml file looks like:
<?xml version=”1.0” encoding=”UTF-8”?>
<soapenv:Envelope xmlns:soapenv=”http://www.w3.org/2003/05/soap-envelope
xmlns:wsa=”http://www.w3.org/2005/08/addressing”>
<soapenv:Header>
<wsa:To>https://test-bramka.edeklaracje.gov.pl</wsa:To&gt;
<wsa:MessageID>urn:uuid:1111111</wsa:MessageID>
<wsa:Action>urn:sendUnsignDocument</wsa:Action>
</soapenv:Header>
<soapenv:Body>
<ns1:sendUnsignDocument xmlns:ns1="https://test-bramka.edeklaracje.gov.pl/xsd"&gt; <ns1:document>PD94bWwgdmVyc2lvbj2UMS4wlCBlbmNvZGluZz2UVVRGLTiUPz4NCjxEZWtsYXJhY2phPg0KCTxOYWdsb3dlaz4NCgkJPEtvZEZvcm11bGFyemEga29kUG9kYXRrdT0iUElUIiBrb2RTeXN0ZW1vd3k9IlBJVC0zNyAoMTYpIiByb2R6YWpab2Jvd2lhemFuaWE9IloiDQp3ZXJzamFTY2hlbXk9IjEtMCI+UElULTM3PC9Lb2RGb3JtdWxhcnphPg0KCQk8V2FyaWFudEZvcm11bGFyemE+MTY8L1dhcmlhbnRGb3JtdWxhcnphPg0KCQk8Q2VsWmxvemVuaWEgcG96PSJQXzEwIj4xPC9DZWxabG96ZW5pYT4NCgkJPFJvaz4yMDEwPC9Sb2s+DQoJCTxLb2RVcnplZHU+MDIwMjwvS29kVXJ6ZWR1Pg0KCTwvTmFnbG93ZWs+DQo8UG9kbWlvdDEgc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endUnsignDocument>
</soapenv:Body>
</soapenv:Envelope>

In NAV i have:

//CREATE(xmlSchema);
CREATE(locautXmlDoc);

//locautXmlDoc.schemas := xmlSchema;
locautXmlDoc.async := FALSE;
locautXmlDoc.loadXML('D:\send.xml');

//MESSAGE(FORMAT(locautXmlDoc.parseError));

IF NOT ISCLEAR(WinHTTPRequest) THEN CLEAR(WinHTTPRequest);
CREATE(WinHTTPRequest);

WinHTTPRequest.Open('GET', 'https://test-bramka.edeklaracje.gov.pl/uslugi/dokumenty',FALSE); //or 'POST'
WinHTTPRequest.SetClientCertificate('LOCAL_MACHINE\My\Certificates'); <----MY Question
WinHTTPRequest.Send;
IF NOT WinHTTPRequest.WaitForResponse() THEN
ERROR('Timed out');

MESSAGE('Status: '+FORMAT(WinHTTPRequest.Status())+'\'+
'StatusText: '+WinHTTPRequest.StatusText());



ERROR:
The call to member Send failed. Returned the Following WinHttp.WinHttpRequest message: Certificate Authority is invalid or incorrect.


1. On page 25/38 are about how to establish the session. But hell I'dont know how make use of it.
2. So i can open https://test-bramka.edeklaracje.gov.pl/uslugi/dokumenty, save the certificate on disk. Next run command prompt: mmc ->
File,Add, Certificate, Local Account, Local Computer. Next click on added certificate, Personal, All Tasks, Imports. So I can add a previously saved certificate.
But how to benefit from this in the code? In HKEY_LOCAL_MACHINE do not have such thing as a Personal ... ([url=Http://msdn.microsoft.com/en-us/library/aa384055]Http://msdn.microsoft.com/en-us/library/aa384055[/url]% 28VS.85% 29.aspx) // Select a client certificate. HttpReq.SetClientCertificate("LOCAL_MACHINE\\Personal\\My Middle-Tier Certificate");

Comments

  • maniekbmaniekb Member Posts: 15
    Anybody? Pls read questions
  • maniekbmaniekb Member Posts: 15
    Maybe someone know how to use SetClientCertificate object -> 'Microsoft WinHTTP Services, version 5.1'.WinHttpRequest ?
    Today I generate free certificate https://www.startssl.com/?app=12; I have this on browser, i can backup to file, very similar situation (http://www.advancedqtp.com/forums/index ... pic=5474.0).
    According to artice: http://msdn.microsoft.com/en-us/library ... 85%29.aspx in regedit, i don't have such a thing:
    "LOCAL_MACHINE\\Personal\\My Middle-Tier Certificate"

    setcert.th.png
  • vitmalvitmal Member Posts: 5
    Hi, unfortunately I don't know solution. I have the same problem. I would like to say only my NAV code can consume webservice if I don't specify certificate via SetClientCertificate method. If I specify certificate I get the same error. I really have not found solution even I specify certificate (the parameter of SetClientCertificate method) in very many forms. Does know someone solution please?
  • deV.chdeV.ch Member Posts: 543
    Just a wild guess, but isn't that "LOCAL_MACHINE\\Personal\\My Middle-Tier Certificate" the path to the certificate in the certification store? Registry has nothing to do with certificates as of my understanding...

    And LOCAL_MACHINE is no registry root, instead it would be HKEY_LOCAL_MACHINE

    Watch your certification store, there should be a "Personal" Dir, this should be the one of the example.
  • mdPartnerNLmdPartnerNL Member Posts: 802
    Shouldn't you send the xml too? like WinHTTPRequest.Send(xmlfile);
Sign In or Register to comment.