Reputation: 273
in order to check validation of turkish personal identification numbers, the gouverment in turkey has this free service: https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx?op=TCKimlikNoDogrula
over SOAP you may check wether or not a ID-Number is valid.
but how ever i can not use this service with this code
package sevsoap;
import javax.xml.soap.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
public class SevSOAP
{
public static void main(String args[])
{
try
{
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
String url = "https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx?op=TCKimlikNoDogrula";
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);
// Process the SOAP Response
printSOAPResponse(soapResponse);
soapConnection.close();
}
catch(Exception e)
{
System.err.println("Error occurred while sending SOAP Request to Server");
e.printStackTrace();
}
}
private static SOAPMessage createSOAPRequest() throws Exception
{
SOAPMessage message = MessageFactory.newInstance().createMessage();
SOAPPart soapPart = message.getSOAPPart();
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");
envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("TCKimlikNoDogrula");
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("TCKimlikNo");
soapBodyElem1.addTextNode("10000000146");
SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("Ad");
soapBodyElem2.addTextNode("Mustafa");
SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("Soyad");
soapBodyElem3.addTextNode("Atatürk");
SOAPElement soapBodyElem4 = soapBodyElem.addChildElement("DogumYili");
soapBodyElem4.addTextNode("1881");
MimeHeaders headers = message.getMimeHeaders();
headers.addHeader("SOAPAction", "http://tckimlik.nvi.gov.tr/WS/TCKimlikNoDogrula");
message.saveChanges();
/* Print the request message */
System.out.print("Request SOAP Message = ");
message.writeTo(System.out);
System.out.println();
return message;
}
/**
* Method used to print the SOAP Response
*/
private static void printSOAPResponse(SOAPMessage soapResponse) throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = soapResponse.getSOAPPart().getContent();
System.out.print("\nResponse SOAP Message = ");
StreamResult result = new StreamResult(System.out);
transformer.transform(sourceContent, result);
}
}
The message is sent in the following format:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<TCKimlikNoDogrula>
<TCKimlikNo>10000000146</TCKimlikNo>
<Ad>Mustafa</Ad>
<Soyad>Atatürk</Soyad>
<DogumYili>1881</DogumYili>
</TCKimlikNoDogrula>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
but it seems like the server requires me to send my query only in the following format:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<TCKimlikNoDogrula xmlns="http://tckimlik.nvi.gov.tr/WS">
<TCKimlikNo>10000000146</TCKimlikNo>
<Ad>Mustafa</Ad>
<Soyad>Atatürk</Soyad>
<DogumYili>1881</DogumYili>
</TCKimlikNoDogrula>
</soap:Body>
</soap:Envelope>
It doesn't matter to what i am changing the Namespace, it still puts out this error from the server:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Server was unable to process request. ---> T.C. Kimlik No değeri 10000000000 değerinden büyük veya eşit ve 89999999999 değerinden küçük veya eşit olmalıdır.
T.C. Kimlik No alanına girdiğiniz değer geçerli bir T.C. Kimlik Numarası değildir.
Ad alanını boş geçemezsiniz.
Soyad alanını boş geçemezsiniz.
Doğum Yıl değeri 1000 değerinden büyük veya eşit ve 9999 değerinden küçük veya eşit olmalıdır.
</faultstring>
<detail/>
</soap:Fault>
</soap:Body>
</soap:Envelope>
It says that i can't submit these variables empty, they must contain data in order to process my query.
So, what could i do in this case?
Upvotes: 2
Views: 543
Reputation: 1738
Missing one default namespace in your code. Please try it!
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("TCKimlikNoDogrula", "", "http://tckimlik.nvi.gov.tr/WS");
(...)
I use empty string for default namespace. I tried your code with this modification and I get this response:
Response SOAP Message = <?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><TCKimlikNoDogrulaResponse xmlns="http://tckimlik.nvi.gov.tr/WS"><TCKimlikNoDogrulaResult>false</TCKimlikNoDogrulaResult></TCKimlikNoDogrulaResponse></soap:Body></soap:Envelope>
Upvotes: 0
Reputation: 8617
I am in a habit of generating WS clients through eclipse, it did all the hard work for me here as well. Below are the step by step instructions how you create them:
Please note the changed url for direct wsdl I have used here: https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx?wsdl
Then I write your caller, below is the entire code:
package tr.gov.nvi.tckimlik.WS;
public class TurkishWS {
public static void main(String args[]) {
try {
KPSPublicLocator loc = new KPSPublicLocator();
KPSPublicSoap soap = loc.getKPSPublicSoap();
boolean ret = soap.TCKimlikNoDogrula(new Long("10000000146"),
"Mustafa", "Atatürk", 1881);
System.out.println("My return : " + ret);
} catch (Exception e) {
System.err
.println("Error occurred while sending SOAP Request to Server");
e.printStackTrace();
}
}
}
The result:
My return : false
I have also tried the direct request through soapUI, below are the request and response:
soapUI Request
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ws="http://tckimlik.nvi.gov.tr/WS">
<soap:Header/>
<soap:Body>
<ws:TCKimlikNoDogrula>
<ws:TCKimlikNo>10000000146</ws:TCKimlikNo>
<!--Optional:-->
<ws:Ad>Mustafa</ws:Ad>
<!--Optional:-->
<ws:Soyad>Atatürk</ws:Soyad>
<ws:DogumYili>1881</ws:DogumYili>
</ws:TCKimlikNoDogrula>
</soap:Body>
</soap:Envelope>
soapUI Response
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<TCKimlikNoDogrulaResponse xmlns="http://tckimlik.nvi.gov.tr/WS">
<TCKimlikNoDogrulaResult>false</TCKimlikNoDogrulaResult>
</TCKimlikNoDogrulaResponse>
</soap:Body>
</soap:Envelope>
Hope it helps your cause, and good luck!
Upvotes: 2