Delphi 2009 imported the UPS WSDL without any errors, and I managed to invoke the web service with my account information and an example parcel ID. The response from the server is:
<detail>
<err:Errors xmlns:err="http://www.ups.com/XMLSchema/XOLTWS/Erro开发者_JAVA百科r/v1.1">
<err:ErrorDetail>
<err:Severity>Hard</err:Severity>
<err:PrimaryErrorCode>
<err:Code>9150002</err:Code>
<err:Description>Invalid or missing inquiry number - TrackingNumber, ShipmentIdentificationNumber, or ReferenceNumber</err:Description>
</err:PrimaryErrorCode>
</err:ErrorDetail>
</err:Errors>
</detail>
Has somebody already sucessfully used the UPS Parcel Tracking web service with a Delphi client, and knows what is wrong?
Here is the client code:
var
Service: TrackPortType;
MyRequest: TrackRequest;
Security: UPSSecurity;
MyResponse: TrackResponse;
ReqOpt: Array_Of_string;
begin
Service := (HTTPRIO1 as TrackPortType);
Security := UPSSecurity.Create;
Security.UsernameToken := UsernameToken.Create;
Security.UsernameToken.Username := 'username';
Security.UsernameToken.Password := 'password';
Security.ServiceAccessToken := ServiceAccessToken.Create;
Security.ServiceAccessToken.AccessLicenseNumber := 'licensenumber';
MyRequest := TrackRequest.Create;
SetLength(ReqOpt, 1);
ReqOpt[0] := '0';
MyRequest.Request := Request.Create;
MyRequest.Request.RequestOption := ReqOpt;
MyRequest.TrackingOption := '02';
MyRequest.InquiryNumber := '1Z...';
try
(Service as ISoapHeaders).Send(Security);
MyResponse := Service.ProcessTrack(MyRequest, nil);
except
on E:ERemotableException do
begin
Memo1.Lines.Text := FormatXmlData(E.FaultDetail);
end;
end;
Solved it with the Java API for XML Web Services (JAX-WS).
To integrate with Delphi, I proxy it as an Intranet Servlet. The Delphi GUI application then can use a simple HTTP request to query the tracking status.
Update: in a second attempt to get it working in Delphi, I hardcoded the SOAP XML request body, and used Indy and XMLDocument instead of the Delphi SOAP library.
精彩评论