DELPHI 为何调用C#的WEBSVR不成功?
推荐一个我自己做的一个电影站,绝对没弹窗:-) www.fastdy.com 速看电影吧,每天都更新,
最新的电影电视剧都在速看电影吧!~
项目中需要 D来调用后台查询,本打算用SOCKET方法,后来想想还是用WEBSVR,因为都是可以直接联网,也有现成的DEMO程序
但是在调用过程中发现,要么就发现XTML包不对,要么就是编码直接有问题,后来在WSDL自动创建的语句中加入两句话就可以解决这个问题了,标红色字体为自加,其他未机器自生成,
附以下代码
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://localhost:2503/DrpWebService/Service.asmx?wsdl
// Encoding : utf-8
// Version : 1.0
// (2010-03-29 10:49:36 - $Revision: 1.9.1.0.1.0.1.9 $)
// ************************************************************************ //
unit Service;
interface
uses InvokeRegistry, 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://tempuri.org/
// soapAction: http://tempuri.org/GetOrderformState
// transport : http://schemas.xmlsoap.org/soap/http
// binding : ServiceSoap
// service : Service
// port : ServiceSoap
// URL : http://localhost:2503/DrpWebService/Service.asmx
// ************************************************************************ //
ServiceSoap = interface(IInvokable)
['{77573149-9C57-FA51-F11F-EFD527C91BD9}']
function GetOrderformState(const inputstr: string): string; stdcall;
end;
function GetServiceSoap(UseWSDL: Boolean = System.False; Addr: string = ''): ServiceSoap;
implementation
uses SOAPHTTPClient;
function GetServiceSoap(UseWSDL: Boolean; Addr: string): ServiceSoap;
const
defWSDL = 'http://22.22.22.49/DelphiWSTest/Service.asmx?wsdl';
defURL = 'http://22.22.22.49/DelphiWSTest/Service.asmx';
defSvc = 'Service';
defPrt = 'ServiceSoap';
var
RIO: THTTPRIO;
begin
Result := nil;
if (Addr = '') then
begin
if UseWSDL then
Addr := defWSDL
else
Addr := defURL;
end;
RIO := THTTPRIO.Create(nil);
try
if UseWSDL then
begin
RIO.HTTPWebNode.UseUTF8InHeader := True;
RIO.WSDLLocation := Addr;
RIO.Service := defSvc;
RIO.Port := defPrt;
end else
RIO.URL := Addr;
Result := (RIO as ServiceSoap);
finally
if Result = nil then
RIO.Free;
end;
end;
initialization
InvRegistry.RegisterInterface(TypeInfo(ServiceSoap), 'http://tempuri.org/', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ServiceSoap), 'http://tempuri.org/GetOrderformState');
InvRegistry.RegisterInvokeOptions(TypeInfo(ServiceSoap), ioDocument);
end.