Delphi调用基于CXF创建的Web Service问题

 

1.  Encoding编码问题

 

2009-8-19 19:19:49 org.apache.cxf.interceptor.LoggingInInterceptor logging

信息: Inbound Message

----------------------------

ID: 1

Address: /HelloWorld

Encoding: ISO-8859-1

Content-Type: text/xml

Headers: {content-type=[text/xml], connection=[Keep-Alive], Host=[192.168.3.101], Content-Length=[500], SOAPAction=[""], User-Agent=[Borland SOAP 1.2], Content-Type=[text/xml], Cache-Control=[no-cache]}

Payload: <?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" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><NS1:sayHi xmlns:NS1="cds.ws"><aName xsi:type="xsd:string">OK</aName><bName xsi:type="xsd:string">not</bName></NS1:sayHi></SOAP-ENV:Body></SOAP-ENV:Envelope>

 

--------------------------------------

2009-8-19 19:19:49 org.apache.cxf.interceptor.LoggingOutInterceptor$LoggingCallback onClose

信息: Outbound Message

---------------------------

ID: 1

Encoding: ISO-8859-1

Content-Type: text/xml

Headers: {}

Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:sayHiResponse xmlns:ns1="cds.ws"><return>&#x4f60;&#x597d;, OK, not</return></ns1:sayHiResponse></soap:Body></soap:Envelope>

--------------------------------------

 

 

Delphi使用WSDLImp.exe导入接口后生成的接口文件中添加

...

 

Result := (RIO as IHelloWorld);

if UseWSDL then

begin

    RIO.WSDLLocation := Addr;

    RIO.Service := defSvc;

    RIO.Port := defPrt;

end else

    RIO.URL := Addr;

RIO.HTTPWebNode.UseUTF8InHeader := true;    //<- 添加


添加语句以后

Encoding: UTF-8

 

 

2. 调用方法返回null值问题

 

调用不成功的消息

 

2009-8-19 18:50:22 org.apache.cxf.interceptor.LoggingInInterceptor logging

信息: Inbound Message

----------------------------

ID: 1

Address: /HelloWorld

Encoding: UTF-8

Content-Type: text/xml; charset="utf-8"

Headers: {content-type=[text/xml; charset="utf-8"], connection=[Keep-Alive], Host=[192.168.3.101], Content-Length=[318], SOAPAction=[""], User-Agent=[Borland SOAP 1.2], Content-Type=[text/xml; charset="utf-8"], Cache-Control=[no-cache]}

Payload: <?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><sayHi xmlns="cds.ws"><aName>OK</aName><bName>not</bName></sayHi></SOAP-ENV:Body></SOAP-ENV:Envelope>

 

--------------------------------------

2009-8-19 18:50:22 org.apache.cxf.interceptor.LoggingOutInterceptor$LoggingCallback onClose

信息: Outbound Message

---------------------------

ID: 1

Encoding: UTF-8

Content-Type: text/xml

Headers: {}

Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:sayHiResponse xmlns:ns1="cds.ws"><return>你好, null, null</return></ns1:sayHiResponse></soap:Body></soap:Envelope>

--------------------------------------

 

调用成功的消息

 

 

2009-8-19 19:19:49 org.apache.cxf.interceptor.LoggingInInterceptor logging

信息: Inbound Message

----------------------------

ID: 1

Address: /HelloWorld

Encoding: ISO-8859-1

Content-Type: text/xml

Headers: {content-type=[text/xml], connection=[Keep-Alive], Host=[192.168.3.101], Content-Length=[500], SOAPAction=[""], User-Agent=[Borland SOAP 1.2], Content-Type=[text/xml], Cache-Control=[no-cache]}

Payload: <?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" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><NS1:sayHi xmlns:NS1="cds.ws"><aName xsi:type="xsd:string">OK</aName><bName xsi:type="xsd:string">not</bName></NS1:sayHi></SOAP-ENV:Body></SOAP-ENV:Envelope>

 

--------------------------------------

2009-8-19 19:19:49 org.apache.cxf.interceptor.LoggingOutInterceptor$LoggingCallback onClose

信息: Outbound Message

---------------------------

ID: 1

Encoding: ISO-8859-1

Content-Type: text/xml

Headers: {}

Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:sayHiResponse xmlns:ns1="cds.ws"><return>&#x4f60;&#x597d;, OK, not</return></ns1:sayHiResponse></soap:Body></soap:Envelope>

--------------------------------------

 

 

调用不成功是由于Delphi发送的SOAP包中的命名空间与服务器上的命名空间不一致。

 

 

Delphi使用WSDLImp.exe导入接口后生成的接口文件中添加soRootRefNodesToBody以后就可以正常返回结果了

...

try

    Result := (RIO as IHelloWorld);

    if UseWSDL then begin

        RIO.WSDLLocation := Addr;

        RIO.Service := defSvc;

        RIO.Port := defPrt;

    end else

        RIO.URL := Addr;

        RIO.HTTPWebNode.UseUTF8InHeader := true;

        //添加生成SOAP消息格式的选择,可以解决返回null值问题。.net中可以可以设置soRootRefNodesToBody解决返回null问题

        RIO.Converter.Options := [soSendMultiRefObj, soTryAllSchema, soRootRefNodesToBody,

            soUTF8InHeader, soCacheMimeResponse, soUTF8EncodeXML];

finally

    if (Result = nil) and (HTTPRIO = nil) then

        RIO.Free;

end;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

麦客来了

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值