开发者

How do I get the namespaces right when using a Transaction Exchange Server Web service?

I am trying to consume a TxServer web service, but I'm getting the error response

Unmarshalling Error: unexpected element (uri: "http://txserver.sut.softekpr.com/1", local:"transaction"). Expected elements are<{}transaction>`.

I found out the XML that Delphi generates does not work with the service,

but if I add xmlns="" to the transaction tag, it works.

Can anyone help me to add xmlns="" to the transaction tag?

I'd like to have: <transaction xmlns="">.

BTW I tried changing: InvRegistry.RegisterInvokeOptions(TypeInfo(TxServer), ioDocument); to all the io.. Options, but it doesn't work.

<?xml version="1.0"?>
<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:Body>
    <requestIVULoto xmlns="http://txserver.sut.softekpr.com/1">
      <transaction>
        <merchantId>00000000000</merchantId>
        <municipalTax>.01</municipalTax>
        <stateTax>开发者_开发知识库;.06</stateTax>
        <subTotal>1</subTotal>
        <tenderType>CASH</tenderType>
        <terminalId>POS02</terminalId>
        <terminalPassword/>
        <total>1.07</total>
        <txDate>2011-05-05T10:02:17.708Z</txDate>
        <txType>SALE</txType>
      </transaction>
    </requestIVULoto>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>


RemClassRegistry.RegisterXSClass(InstitutionCode, #0, 'InstitutionCode');

where InstitutionCode is some node name, #0 empty char, simply empty string '' not working it is replaced by generated name.

It can be problem with widestring, but you can use TXSString instead


Use an OnBeforePost event on the RIO object, and simply edit the outgoing string. It's dirty, but it works.

procedure TMyHandler.RIO_BeforeExecute(const MethodName: string; var SOAPRequest: WideString);
begin
  SOAPRequest := StringReplace(SOAPRequest,'<transaction>','<transaction xmlns="">',[]);
end;

Here is an example of hooking the RIO via the GUI way: http://www.onlinedelphitraining.com/newsletters/webservices.htm

Here is discussion on doing it in code: THttprio onBeforeExecute changing the soapRequest


Then try to use THTTPRIO component, if you have it in your Delphi distribution and try to pass it into the GetTxServer method call.

...
var MyTxServer: TxServer;
begin
  MyTxServer := GetTxServer(True, '', HTTPRIO1); // HTTPRIO1 is your component
end;

And as Chris mentioned before you can change the request in OnBeforeExecute event (of that HTTPRIO component); I have D2009 so you will probably have different parameters if you have it at all.

procedure TForm10.HTTPRIO1BeforeExecute(const MethodName: string;
  SOAPRequest: TStream);
var MyStringList: TStringList;

begin
  MyStringList := TStringList.Create;
  SOAPRequest.Position := 0;
  MyStringList.LoadFromStream(SOAPRequest);
  MyStringList.Text := StringReplace(MyStringList.Text, '<transaction>', '<transaction xmlns="">', [RfReplaceAll]);
  SOAPRequest.Position := 0;
  MyStringList.SaveToStream(SOAPRequest);
end;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜