开发者

How can i import a https webservice (wcf) with Delphi 2010?

I have a problem so i wanna help from you. There is a webservice and it's url : https://kps.saglik.gov.tr/Services/KPSTestServices.svc

We can import this url on visual studio c# easily, but we couldn't import it on delphi 2010.

Also we have a user id and password from saglik.gov.tr, but the result is same : can't import this service. What can we do now ?

Thanks for any idea from at the moment.

Visual Studio Sample : https://kps.saglik.gov.tr/kps_ornek1.zip


I was able to import files to your local hard disk recording.

  • https://kps.saglik.gov.tr/Services/KPSTestServices.svc?wsdl = services.wsdl
  • https://kps.saglik.gov.tr/Services/KPSTestServices.svc?wsdl=wsdl0 = secondry.wsdl
  • https://kps.saglik.gov.tr/Services/KPSTestServices.svc?xsd=xsd0 = xsd0.xsd
  • https://kps.saglik.gov.tr/Services/KPSTestServices.svc?xsd=xsd1 = xsd1.xsd
  • https://kps.saglik.gov.tr/Services/KPSTestServices.svc?xsd=xsd2 = xsd2.xsd

When I call service , Now I get the https connection failed error.

Xml created by the WCFStorm (http://www.wcfstorm.com/wcf/home.aspx)

Header 

POST https://kps.saglik.gov.tr/Services/KPSTestServices.svc HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
Host: kps.saglik.gov.tr
Content-Length: 1256
Expect: 100-continue
Connection: Keep-Alive


<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="h开发者_开发问答ttp://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><s:Header><a:Action s:mustUnderstand="1">http://www.saglik.gov.tr/KPS/2011/KPSServices/TcKimlikNoIleKisiSorgula</a:Action><a:MessageID>urn:uuid:b99c1ef4-9e44-42b9-ae1f-9844bfc0f997</a:MessageID><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">https://kps.saglik.gov.tr/Services/KPSTestServices.svc</a:To><o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><u:Timestamp u:Id="_0"><u:Created>2011-09-13T11:17:27.234Z</u:Created><u:Expires>2011-09-13T11:22:27.234Z</u:Expires></u:Timestamp><o:UsernameToken u:Id="uuid-d7a725d3-aa3c-4336-8651-304ecdb8d5e0-4"><o:Username>myUserName</o:Username><o:Password o:Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">myPassword</o:Password></o:UsernameToken></o:Security></s:Header><s:Body><TcKimlikNoIleKisiSorgula xmlns="http://www.saglik.gov.tr/KPS/2011"><tcNo>1842715****</tcNo></TcKimlikNoIleKisiSorgula></s:Body></s:Envelope>

Response XML

Header
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 1519
Content-Type: application/soap+xml; charset=utf-8
Server: Microsoft-IIS/7.5
Set-Cookie: ASP.NET_SessionId=0vdbbkozgztz4falycku4gr0; path=/; HttpOnly
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 13 Sep 2011 11:19:40 GMT

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><s:Header><a:Action s:mustUnderstand="1">http://www.saglik.gov.tr/KPS/2011/KPSServices/TcKimlikNoIleKisiSorgulaResponse</a:Action><a:RelatesTo>urn:uuid:b99c1ef4-9e44-42b9-ae1f-9844bfc0f997</a:RelatesTo><o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><u:Timestamp u:Id="_0"><u:Created>2011-09-13T11:19:41.255Z</u:Created><u:Expires>2011-09-13T11:24:41.255Z</u:Expires></u:Timestamp></o:Security></s:Header><s:Body><TcKimlikNoIleKisiSorgulaResponse xmlns="http://www.saglik.gov.tr/KPS/2011"><TcKimlikNoIleKisiSorgulaResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Hata i:nil="true"/><Sonuc><Ad>MUSTAFA</Ad><AileSiraNo>12</AileSiraNo><AnaAd>LEYLA</AnaAd><BabaAd>OSMAN</BabaAd><BireySiraNo>*</BireySiraNo><CiltAd>-</CiltAd><CiltKod>-</CiltKod><Cinsiyet>Erkek</Cinsiyet><Din i:nil="true"/><DogumTarihi>21.9.0000</DogumTarihi><DogumYer>*</DogumYer><Durum>Açık</Durum><Hata i:nil="true"/><IlAd>*</IlAd><IlKod>*</IlKod><IlceAd>Abana</IlceAd><IlceKod>*</IlceKod><MedeniHal>Bekar</MedeniHal><OlumTarih>0.0.0</OlumTarih><Soyad>*</Soyad><TCKimlikNo>18427***</TCKimlikNo><Yakinlik>Kendisi</Yakinlik></Sonuc></TcKimlikNoIleKisiSorgulaResult></TcKimlikNoIleKisiSorgulaResponse></s:Body></s:Envelope>

Delphi 2010

My Request

CONNECT kps.saglik.gov.tr:443 HTTP/1.0
User-Agent: Borland SOAP 1.2
Host: kps.saglik.gov.tr:443
Content-Length: 0
Proxy-Connection: Keep-Alive
Pragma: no-cache

No XML

My Response

Header 
HTTP/1.1 502 Unable to Secure Connection
Via: 1.1 SYSTMG07
Connection: Keep-Alive
Proxy-Connection: Keep-Alive

No XML


You need to point delphi towards the WSDL of the service. just append ?wsdl to the end of the first URL you gave: https://kps.saglik.gov.tr/Services/KPSTestServices.svc?wsdl and open this URL.

Save the file as a wsdl file and import it using: File -> New -> Other -> Delphi Projects -> Webservices -> WSDL Importer.

Please note: when the webservice changes you need to reimport. Also, using the webservice this way, you might need to deploy the wsdl with your application, depending on wether or not you are using the wsdl when consuming the webservice.


Maybe I am a little bit pessimistic about Delphi SOAP support, but I think this will be easier to solve using a "proxy" service written in C# (or Java, depending on available developer resources).

I have used a 'proxy' solution succesfully for the integration of a Microsoft Dynamics CRM system. After many attempts to solve it in Delphi, we finally wrote a simple C# application which reads input data from files (created from the Delphi app) and then invokes the web service operations using the data from these files.

Fortunately this was only a very simple one-way interface. For advanced requirements, the Delphi app could communicate over a TCP based protocol (HTTP) using XML or JSON payload. For bidirectional data exchange, the Delphi application would have to run a HTTP server too, which can be implemented with Indy in a couple of code lines. For bidirectional operation, using a messaging middleware like MSMQ (or one of the many open source message brokers like ActiveMQ or OpenMQ) can also be a good solution, because all applications can go offline for maintenance without the danger of message loss.


I just went through a similar problem attempting to connect a D2007 client to a C# service. The details I found were interesting. First of all the Delphi importer seriously under performed. I switched to RemObj and continued to have problems. At the end of the day there seems to be 3 items of interest when making the call to a WCF C# web service from a Delphi App. Those 3 items are as follows...

1) Make sure on the Delphi side you have the Soap version set to 1.2 (this is the easy one)

2) The post command being generated was including an incorrect action. needed: POST "http://URI/Service/Command" RemObj: POST urn:HCSConnect-WSHCSConnect#Ping Delphi: ---post command missing completely---

What I did was change some details in the Rem Obj stuff and make it look like what I needed

3) With the service I was using the soap envelope wants a header area that contains a definition of a few details. In my situation the most important items in this header turned out to be the "a:Action" and "a:To" tags. These tags are missing in the Delphi apps, RemObj or otherwise. So in my situations I am intercepting the xml and filling it in.

The solutions to the last 2 items are not so simple... if you are using Rem Obj you can read about how I fixed it and what you can do the RemObj forum.

http://connect.remobjects.com/discussion/825/problem-calling-web-service-built-with-c

.... last but not least ...

I also got the thing to work using direct calls... if you are not using RemObj and Delphi is being a pain you can always just build your post and xml yourself and send it. Just like I did below... remember, post/xml/web it's all just plain text being sent back and forth.

procedure TMainForm.Button5Click(Sender: TObject);
  procedure HandleError(const errorCode: integer);
  var
    errorMessage: AnsiString;
  begin
    SetLength(errorMessage, 256);
    FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_FROM_HMODULE,
                   Pointer(GetModuleHandle('wininet.dll')),
                   errorCode, 0, PChar(errorMessage), Length(errorMessage), nil);
    SetLength(errorMessage, StrLen(PChar(errorMessage)));
    raise Exception.Create(errorMessage);
  end;

  function BuildHeader: TStringStream;
  begin
    result := TStringStream.Create('');
    try
      result.WriteString('Content-Type: application/soap+xml;charset=UTF-8;action="http://Thermo.Connect/IHCSConnect/Ping"' + sLineBreak);
    except
      result.Free;
      raise;
    end;
  end;

  function BuildBody: TStringStream;
  begin
    result := TStringStream.Create('');
    with result do
      try
        WriteString('<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">' + sLineBreak);
        WriteString('<s:Header>' + sLineBreak);
        WriteString('<a:Action>http://Thermo.Connect/IHCSConnect/Ping</a:Action>' + sLineBreak);
        WriteString('<a:To>http://thermo-pc:2021/WSHCSConnect</a:To>' + sLineBreak);
        WriteString('</s:Header>' + sLineBreak);
        WriteString('<s:Body>' + sLineBreak);
        WriteString('<Ping xmlns="http://Thermo.Connect">' + sLineBreak);
        WriteString('</Ping>' + sLineBreak);
        WriteString('</s:Body>' + sLineBreak);
        WriteString('</s:Envelope>' + sLineBreak);
      except;
        result.Free;
        raise;
      end;
  end;

var
  InetRoot: HINTERNET;
  InetConnect: HINTERNET;
  Request: HINTERNET;
begin
  InetRoot := InternetOpen('GabeCode', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  try
    InetConnect := InternetConnect( InetRoot, 'thermo-pc:2021', 0, '',
                                    '', INTERNET_SERVICE_HTTP, 0, Cardinal(Self));
    try
      Request := HttpOpenRequest( InetConnect, 'POST', 'WSHCSConnect', 'HTTP/1.1', nil, nil,
                                  INTERNET_FLAG_KEEP_CONNECTION or INTERNET_FLAG_NO_CACHE_WRITE,
                                  0);
      try
        // build add header items to the post request
        with BuildHeader do
        try
          HttpAddRequestHeaders(Request, PChar(DataString), Length(DataString), HTTP_ADDREQ_FLAG_ADD);
        finally
          Free;
        end;

        // build the body of data being posted and send the post
        with BuildBody do
        try
          if not HttpSendRequest(Request, nil, 0, PChar(DataString), Length(DataString)) then
            HandleError(GetLastError);
        finally
          Free;
        end;

      finally
        InternetCloseHandle(Request);
      end;
    finally
      InternetCloseHandle(InetConnect);
    end;
  finally
    InternetCloseHandle(InetRoot);
  end;
end;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜