D6 prof.
We must use a SOAP XML service. I tried to import wsdl, and use the interface generated by Delphi, but it is failed.
And: as I see I must provide username and password in an XML section, but I don't know how to do with this automatic interface...
I determined that I provide the XML by hand. It is not problem, the problem is how to post into server... The wsdl import knows how to call the server. It is know the url, port, etc.
I want to write my own code. As I think SOAP calls are uses "Post" method what I can do easily. But what parameter is needed for post? Which parameters is what read by SOAP server?
To understand what I talking about it, see this code (FParams : TStrings):
procedure TDDHTTPObject.Post;
var
WinHttpReq : variant;
posts : string;
begin
Result := '';
WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
try
posts := EncodeParamsToURL(FParams);
URL := URL + '?' + posts;
WinHttpReq.Open('POST', URL, false);
WinHttpReq.Send();
Result := WinHttpReq.ResponseText;
finally
WinHttpReq := 0;
end;
end;
For example:
Params['data'] = xmlstring;
or
Params['soap'] = xmlstring;
Do you know something about it?
If you use .NET as your web server you can see the Methods and raw XML when you browse to the WS URL ie: http://yourdomain.com/ws/ApplicationWebService.asmx
the XML is available for both SOAP 1.1 and 1.2 and it may look like this (SOAP 1.1):
<?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:Header>
<UserIdentificationHeader xmlns="http://yourdomain.com/ws">
<UserAgent>string</UserAgent>
<UserToken>string</UserToken>
</UserIdentificationHeader>
</soap:Header>
<soap:Body>
<MyTestMethod xmlns="http://yourdomain.com/ws" />
</soap:Body>
</soap:Envelope>
Next I use "MSXML2.XMLHTTP" like this:
var
mhttp: OleVariant;
URL := 'http://yourdomain.com/ws/ApplicationWebService.asmx';
mhttp := CreateOleObject('MSXML2.XMLHTTP');
mhttp.Open('POST', URL, False); // False=synchronously
mhttp.setRequestHeader('User-Agent', APP_WS_USER_AGENT); // optional
mhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
mhttp.setRequestHeader('SoapAction', 'http://yourdomain.com/ws/' + 'MyTestMethod');
mhttp.send(TheSOAPXML);
if mhttp.Status = 202 then ShowMessage('ACCEPTED OK!');
Instantiate your own THttpRio component and pass it in to the web service call. Use the THttpRio.BeforeExecute event to modify the SOAPRequest stream before it gets sent to the service. Lots of examples out there but look at THttprio onBeforeExecute changing the soapRequest as one to get you going.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With