delphi 调用 java web service(100)

J

jadic

Unregistered / Unconfirmed
GUEST, unregistred user!
web service 服务端是用cxf简单实现的,java作为客户度已经能成功调用但用Delphi作为客户端调用时出错Delphi实现客户端时,直接用Delphi自带的wsdl importor生成接口文件先把wsdl贴出来吧<?xml version="1.0" encoding="UTF-8" ?> - <wsdl:definitions name="HelloWorldImplService" targetNamespace="http://server.cxf.com/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://server.cxf.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">- <wsdl:types>- <xs:schema elementFormDefault="unqualified" targetNamespace="http://server.cxf.com/" version="1.0" xmlns:tns="http://server.cxf.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="sayHi" type="tns:sayHi" /> <xs:element name="sayHiResponse" type="tns:sayHiResponse" /> - <xs:complexType name="sayHi">- <xs:sequence> <xs:element minOccurs="0" name="text" type="xs:string" /> </xs:sequence> </xs:complexType>- <xs:complexType name="sayHiResponse">- <xs:sequence> <xs:element minOccurs="0" name="return" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:schema> </wsdl:types>- <wsdl:message name="sayHiResponse"> <wsdl:part element="tns:sayHiResponse" name="parameters" /> </wsdl:message>- <wsdl:message name="sayHi"> <wsdl:part element="tns:sayHi" name="parameters" /> </wsdl:message>- <wsdl:portType name="HelloWorld">- <wsdl:eek:peration name="sayHi"> <wsdl:input message="tns:sayHi" name="sayHi" /> <wsdl:eek:utput message="tns:sayHiResponse" name="sayHiResponse" /> </wsdl:eek:peration> </wsdl:portType>- <wsdl:binding name="HelloWorldImplServiceSoapBinding" type="tns:HelloWorld"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> - <wsdl:eek:peration name="sayHi"> <soap:eek:peration soapAction="" style="document" /> - <wsdl:input name="sayHi"> <soap:body use="literal" /> </wsdl:input>- <wsdl:eek:utput name="sayHiResponse"> <soap:body use="literal" /> </wsdl:eek:utput> </wsdl:eek:peration> </wsdl:binding>- <wsdl:service name="HelloWorldImplService">- <wsdl:port binding="tns:HelloWorldImplServiceSoapBinding" name="HelloWorldImplPort"> <soap:address location="http://192.168.3.19:9199/helloWorld" /> </wsdl:port> </wsdl:service> </wsdl:definitions>
 
J

jadic

Unregistered / Unconfirmed
GUEST, unregistred user!
delphi生成的接口文件// ************************************************************************ //// The types declared in this file were generated from data read from the// WSDL File described below:// WSDL : http://192.168.3.19:9199/helloWorld?wsdl// Encoding : UTF-8// Version : 1.0// (2010-4-12 16:05:17 - 1.33.2.5)// ************************************************************************ //unit IntfHelloWorld;interfaceuses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;type // ************************************************************************ // // The following types, referred to in the WSDL document are not being represented // in this file. They are either aliases[@] of other types represented or were referred // to but never[!] declared in the document. The types from the latter category // typically map to predefined/known XML or Borland types; however, they could also // indicate incorrect WSDL documents that failed to declare or import a schema type. // ************************************************************************ // // !:string - "http://www.w3.org/2001/XMLSchema" // ************************************************************************ // // Namespace : http://server.cxf.com/ // transport : http://schemas.xmlsoap.org/soap/http // style : document // binding : HelloWorldImplServiceSoapBinding // service : HelloWorldImplService // port : HelloWorldImplPort // URL : http://192.168.3.19:9199/helloWorld // ************************************************************************ // HelloWorld = interface(IInvokable) ['{FD8A0710-486D-67E2-9EDD-8D2655AA62BC}'] function sayHi(const text: WideString): WideString; stdcall; end;function GetHelloWorld(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): HelloWorld;implementationfunction GetHelloWorld(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): HelloWorld;const defWSDL = 'http://192.168.3.19:9199/helloWorld?wsdl'; defURL = 'http://192.168.3.19:9199/helloWorld'; defSvc = 'HelloWorldImplService'; defPrt = 'HelloWorldImplPort';var RIO: THTTPRIO;begin Result := nil; if (Addr = '') then begin if UseWSDL then Addr := defWSDL else Addr := defURL; end; if HTTPRIO = nil then RIO := THTTPRIO.Create(nil) else RIO := HTTPRIO; try Result := (RIO as HelloWorld); if UseWSDL then begin RIO.WSDLLocation := Addr; RIO.Service := defSvc; RIO.Port := defPrt; end else RIO.URL := Addr; finally if (Result = nil) and (HTTPRIO = nil) then RIO.Free; end;end;initialization InvRegistry.RegisterInterface(TypeInfo(HelloWorld), 'http://server.cxf.com/', 'UTF-8'); InvRegistry.RegisterDefaultSOAPAction(TypeInfo(HelloWorld), ''); InvRegistry.RegisterInvokeOptions(TypeInfo(HelloWorld), ioDocument);end.调用代码:type TForm1 = class(TForm) btn1: TButton; procedure btn1Click(Sender: TObject); private { Private declarations } function GetWebService: HelloWorld; public { Public declarations } property WebService: HelloWorld read GetWebService; end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.btn1Click(Sender: TObject);begin Caption := GetWebService.sayHi('Jadic');end;function TForm1.GetWebService: HelloWorld;begin Result := IntfHelloWorld.GetHelloWorld;end;end.调用sayHi接口时会出现这个错unexpected element (uri:"http://server.cxf.com/", local:"text"). Expected elements are <{}text>如果我把接口文件中的最后一行的InvRegistry.RegisterInvokeOptions(TypeInfo(HelloWorld), ioDocument);改成InvRegistry.RegisterInvokeOptions(TypeInfo(HelloWorld), ioLiteral);会出现这个错Message part text was not recognized. (Does it exist in service WSDL?)请问是不是接口文件中还有哪个地方注册还没有写,谢谢指点
 
J

jadic

Unregistered / Unconfirmed
GUEST, unregistred user!
再往上挤下,哪位知道的还请指点下啊
 
J

jadic

Unregistered / Unconfirmed
GUEST, unregistred user!
没人肯答吗
 

舞雪

Unregistered / Unconfirmed
GUEST, unregistred user!
都不需要THTTPRIO?
 
J

jadic

Unregistered / Unconfirmed
GUEST, unregistred user!
有用到啊,接口文件中的GetHelloWorld用到了啊
 
S

shadowpj

Unregistered / Unconfirmed
GUEST, unregistred user!
呵,我刚刚在做这个,我是wsdl importor生成接口文件.pas 再在客户端引用,放上THTTPRIO 控件,设置THTTPRIO的wsdllocation 为你的url 在设置service,port 程序var WebSerivceInterface: WebSerivcePortType;begin WebSerivceInterface:=HTTPRIO1 as WebSerivcePortType; retu:=WebSerivceInterface.sendSMS();//调用接口end;
 
X

xianjun

Unregistered / Unconfirmed
GUEST, unregistred user!
Delphi7不能正常调用太正常不过了。建议使用Delphi 2007来调用,肯定没有问题。
 
J

jadic

Unregistered / Unconfirmed
GUEST, unregistred user!
D7不能调成功吗,我这调C#的没问题啊,就是调Java的不成功,不知道是怎么回事
 
B

boy2002cn

Unregistered / Unconfirmed
GUEST, unregistred user!
只引用IntfHelloWorld 不加THTTPRIO 事件执行var Hw: HelloWorld;//可把这个升级成窗体上的全局变量begin hw:=GetHelloWorld;;//hw是全局变量就把这句移到create或者show事件里,要加上try,可能会连接不上服务器报错 Caption := hw.sayHi('Jadic');end;
 
X

xianjun

Unregistered / Unconfirmed
GUEST, unregistred user!
不是说D7不能调WebService,而是对WebService的版本支持比较低,有一些新的特性它就不识别了。
 
J

jadic

Unregistered / Unconfirmed
GUEST, unregistred user!
但还有奇怪的就是,我调用不需要传参数的接口就能正常,传参数就挂了
 
J

jadic

Unregistered / Unconfirmed
GUEST, unregistred user!
再往上弄一哈
 
顶部