在网上找到的例子 用delphi 基于webservice发送短信
新浪发送短信的Web Service地址是http://smsinter.sina.com.cn/ws/smswebservice0101.wsdl,该Web Service就只有一个方法,即string sendXml(carrier,userid,password,mobilenumber,content,msgtype)。各个参数全部为string类型,其含义基本如下(可能不正确)。 根据提供的例子 我点发送按钮的时候老是会出错不知道为什么,请求大侠指教 另一个是我写的很简单的主窗口文件一个是用delphi WSDL Importer向导根据 新浪web service地址生成的文件
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://smsinter.sina.com.cn/ws/smswebservice0101.wsdl
// Encoding : UTF-8
// Version : 1.0
// (2011-7-20 19:48:37 - 1.33.2.5)
// ************************************************************************ //unit smswebservice0101;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://outlook.microsoft.com/add-ins/SMS/message/
// soapAction: http://outlook.microsoft.com/add-ins/SMS/action/SMSWebService.sendXml
// transport : http://schemas.xmlsoap.org/soap/http
// style : rpc
// binding : SMSWebServiceSoapBinding
// service : SMSWS
// port : SMSWebServiceSoapPort
// URL : http://202.108.35.168/cgi-bin/ws/smswebservice0101
// ************************************************************************ //
SMSWebServiceSoapPort = interface(IInvokable)
['{640A28C1-F5F5-8CD9-06A9-58576FCA9BBA}']
function sendXml(const Carrier: WideString; const Id: WideString; const Password: WideString; const ToMobile: WideString; const Message: WideString; const MsgType: WideString): WideString; stdcall;
end;function GetSMSWebServiceSoapPort(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): SMSWebServiceSoapPort;
implementationfunction GetSMSWebServiceSoapPort(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): SMSWebServiceSoapPort;
const
defWSDL = 'http://smsinter.sina.com.cn/ws/smswebservice0101.wsdl';
defURL = 'http://202.108.35.168/cgi-bin/ws/smswebservice0101';
defSvc = 'SMSWS';
defPrt = 'SMSWebServiceSoapPort';
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 SMSWebServiceSoapPort);
if UseWSDL then
begin
RIO.WSDLLocation := Addr;
RIO.Service := defSvc;
RIO.Port := defPrt;
RIO.HTTPWebNode.Proxy := '192.168.1.132:808'; end else
RIO.URL := Addr;
finally
if (Result = nil) and (HTTPRIO = nil) then
RIO.Free;
end;
end;
initialization
InvRegistry.RegisterInterface(TypeInfo(SMSWebServiceSoapPort), 'http://outlook.microsoft.com/add-ins/SMS/message/', 'UTF-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(SMSWebServiceSoapPort), 'http://outlook.microsoft.com/add-ins/SMS/action/SMSWebService.sendXml');end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, InvokeRegistry, Rio, SOAPHTTPClient;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Memo1: TMemo;
HTTPRIO1: THTTPRIO;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
{$R *.dfm}
uses smswebservice0101;procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Enabled := False;
memo1.Text := GetSMSWebServiceSoapPort.sendXml(Edit1.Text,Edit2.Text,
Edit3.Text,Edit4.Text,Edit5.Text,'Text');
Button1.Enabled :=True;
end;end.编译后点击按钮出现以下问题
新浪发送短信的Web Service地址是http://smsinter.sina.com.cn/ws/smswebservice0101.wsdl,该Web Service就只有一个方法,即string sendXml(carrier,userid,password,mobilenumber,content,msgtype)。各个参数全部为string类型,其含义基本如下(可能不正确)。 根据提供的例子 我点发送按钮的时候老是会出错不知道为什么,请求大侠指教 另一个是我写的很简单的主窗口文件一个是用delphi WSDL Importer向导根据 新浪web service地址生成的文件
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://smsinter.sina.com.cn/ws/smswebservice0101.wsdl
// Encoding : UTF-8
// Version : 1.0
// (2011-7-20 19:48:37 - 1.33.2.5)
// ************************************************************************ //unit smswebservice0101;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://outlook.microsoft.com/add-ins/SMS/message/
// soapAction: http://outlook.microsoft.com/add-ins/SMS/action/SMSWebService.sendXml
// transport : http://schemas.xmlsoap.org/soap/http
// style : rpc
// binding : SMSWebServiceSoapBinding
// service : SMSWS
// port : SMSWebServiceSoapPort
// URL : http://202.108.35.168/cgi-bin/ws/smswebservice0101
// ************************************************************************ //
SMSWebServiceSoapPort = interface(IInvokable)
['{640A28C1-F5F5-8CD9-06A9-58576FCA9BBA}']
function sendXml(const Carrier: WideString; const Id: WideString; const Password: WideString; const ToMobile: WideString; const Message: WideString; const MsgType: WideString): WideString; stdcall;
end;function GetSMSWebServiceSoapPort(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): SMSWebServiceSoapPort;
implementationfunction GetSMSWebServiceSoapPort(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): SMSWebServiceSoapPort;
const
defWSDL = 'http://smsinter.sina.com.cn/ws/smswebservice0101.wsdl';
defURL = 'http://202.108.35.168/cgi-bin/ws/smswebservice0101';
defSvc = 'SMSWS';
defPrt = 'SMSWebServiceSoapPort';
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 SMSWebServiceSoapPort);
if UseWSDL then
begin
RIO.WSDLLocation := Addr;
RIO.Service := defSvc;
RIO.Port := defPrt;
RIO.HTTPWebNode.Proxy := '192.168.1.132:808'; end else
RIO.URL := Addr;
finally
if (Result = nil) and (HTTPRIO = nil) then
RIO.Free;
end;
end;
initialization
InvRegistry.RegisterInterface(TypeInfo(SMSWebServiceSoapPort), 'http://outlook.microsoft.com/add-ins/SMS/message/', 'UTF-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(SMSWebServiceSoapPort), 'http://outlook.microsoft.com/add-ins/SMS/action/SMSWebService.sendXml');end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, InvokeRegistry, Rio, SOAPHTTPClient;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Memo1: TMemo;
HTTPRIO1: THTTPRIO;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
{$R *.dfm}
uses smswebservice0101;procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Enabled := False;
memo1.Text := GetSMSWebServiceSoapPort.sendXml(Edit1.Text,Edit2.Text,
Edit3.Text,Edit4.Text,Edit5.Text,'Text');
Button1.Enabled :=True;
end;end.编译后点击按钮出现以下问题
确少所需的空白
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML
你提供的这个例子,我觉得有些问题,你能用 WSDL importer 自动生成吗?我这边是不行。
还有,调Webservice一定要注意编码格式的问题,什么UTF-8,GB2312啊,如果不注意,很搞人的。我觉得你的问题一个出在这里了。另,你出的分真少……
我这边返回的内容如下:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>500 Internal Server Error</TITLE>
</HEAD><BODY>
<H1>Internal Server Error</H1>
The server encountered an internal error or
misconfiguration and was unable to complete
your request.<P>
Please contact the server administrator,
[email protected] and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.<P>
More information about this error may be available
in the server error log.<P>
<HR>
<ADDRESS>Apache/1.3.37 Server at smsinter.sina.com.cn Port 80</ADDRESS>
</BODY></HTML>上面的内容不重要,因为我没有注册新浪无线的账号,返回错误很正常,但Delphi没有正确的抛出返回的错误,问题就在最上一行的<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">原因应该是Delphi默认的是禁用DTD的,所以如果找到启用DTD的方法,应该就可以解决了,暂时没有找到,下班了,明天再说吧