Delphi调用基于CXF创建的Web Service问题
2009-08-19 19:18
513 查看
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>你好, 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>你好, 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;
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>你好, 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>你好, 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;
相关文章推荐
- 关于C#下写的Web Service 服务在Delphi下调用时的问题
- 关于C#下写的Web Service 服务在Delphi下调用时的问题
- 关于C#下写的Web Service 服务在Delphi下调用时的问题
- 关于C#下写的Web Service 服务在Delphi下调用时的问题
- 关于c#下写的web service 服务在delphi下调用时的问题[转]
- mule 基于wsdl调用cxf web service
- Delphi调用C#dll的问题
- 基于jni调用时,jvm报错问题的深入分析
- 用cxf发布和调用web service
- CXF学习笔记一:如何创建、发布和访问基于CXF的服务
- 基于同一个Table或者TableViewer创建的Table,创建CheckTableViewer引起问题说明
- 多线程委托之跨线程问题分析--在创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvoke(解决方法已更新)
- vs2013 创建调用链接库 没有生成 “.lib” 问题
- Delphi动态调用Java的WebService —— 基于“Axis2发布WebService例子(HelloWorld)”
- 基于vc6.0的创建线程程序的问题,为什么如下程序每次运行的结果会不一样呢?
- Android调用Axis、Axis2、Cxf发布的web service
- SAP创建Web Service以及用ABAP调用
- 在Salesforce中创建Web Service供外部系统调用
- delphi 创建DLL文件 及其调用和注意事项