1,593
社区成员
发帖
与我相关
我的任务
分享
把这个保存一下,然后导入wsdl的时候选择这个文件
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="HelloWorld">
<s:complexType />
</s:element>
<s:element name="HelloWorldResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="HelloWorldSoapIn">
<wsdl:part name="parameters" element="tns:HelloWorld" />
</wsdl:message>
<wsdl:message name="HelloWorldSoapOut">
<wsdl:part name="parameters" element="tns:HelloWorldResponse" />
</wsdl:message>
<wsdl:portType name="Service1Soap">
<wsdl:operation name="HelloWorld">
<wsdl:input message="tns:HelloWorldSoapIn" />
<wsdl:output message="tns:HelloWorldSoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Service1Soap" type="tns:Service1Soap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="HelloWorld">
<soap:operation soapAction="http://tempuri.org/HelloWorld" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="Service1Soap12" type="tns:Service1Soap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="HelloWorld">
<soap12:operation soapAction="http://tempuri.org/HelloWorld" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Service1">
<wsdl:port name="Service1Soap" binding="tns:Service1Soap">
<soap:address location="http://localhost:3075/Service1.asmx" />
</wsdl:port>
<wsdl:port name="Service1Soap12" binding="tns:Service1Soap12">
<soap12:address location="http://localhost:3075/Service1.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
//c#编写webservice
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace WebService1
{
/// <summary>
/// Service1 的摘要说明。
/// </summary>
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
//CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
InitializeComponent();
}
#region 组件设计器生成的代码
//Web 服务设计器所必需的
private IContainer components = null;
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
// WEB 服务示例
// HelloWorld() 示例服务返回字符串 Hello World
// 若要生成,请取消注释下列行,然后保存并生成项目
// 若要测试此 Web 服务,请按 F5 键
[WebMethod]
public string HelloWorld()
{
return "Hello World ";
}
}
}
//import wsdl部分
unit Service1;
interface
uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;
type
Service1Soap = interface(IInvokable)
[ '{CFE467D4-A39E-2BD2-5836-7685A9E27F8D} ']
function HelloWorld: WideString; stdcall;
end;
function GetService1Soap(UseWSDL: Boolean=System.False; Addr: string= ' '; HTTPRIO: THTTPRIO = nil): Service1Soap;
implementation
function GetService1Soap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): Service1Soap;
const
defWSDL = 'http://localhost/WebService1/Service1.asmx?wsdl ';
defURL = 'http://localhost/WebService1/Service1.asmx ';
defSvc = 'Service1 ';
defPrt = 'Service1Soap ';
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 Service1Soap);
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(Service1Soap), 'http://tempuri.org/ ', 'utf-8 ');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(Service1Soap), 'http://tempuri.org/HelloWorld ');
InvRegistry.RegisterInvokeOptions(TypeInfo(Service1Soap), ioDocument);
end.
//调用部分
var
ss:Service1Soap;
RIO : THTTPRIO;
begin
RIO:= THTTPRIO.Create( Owner );
ss:=RIO as Service1Soap;
RIO.WSDLLocation:= 'http://localhost/WebService1/Service1.asmx?wsdl ';
showmessage( ss.HelloWorld );
end;
//结果
Hello World
操作xml你把这个类修改一下
unit XmlParser;
interface
uses
Classes, Records, XMLDoc, XMLIntf;
type
TXmlParser =class( TObject )
private
Xml: TXMLDocument;
strStream:TStringStream;
public
constructor Create( AOwner:TComponent; XmlStr: wideString );
destructor Destroy;override;
procedure GetVehInfo( XmlStr:wideString; var p: PVehInfo );
end;
implementation
{ TXmlParser }
constructor TXmlParser.Create( AOwner: TComponent; XmlStr: wideString );
begin
Xml:= TXMLDocument.Create( AOwner );
strStream:= TStringStream.Create( XmlStr );
Xml.LoadFromStream( strStream, xetUTF_8 );
Xml.Active:= True;
end;
destructor TXmlParser.Destroy;
begin
Xml.Free;
strStream.Free;
inherited;
end;
procedure TXmlParser.GetVehInfo(XmlStr: wideString; var p: PVehInfo);
var
TempXNode,TempXNode1,Node: IXmlNode;
IntI:Integer;
h:Head;
begin
try
TempXNode := Xml.DocumentElement;
Node:= TempXNode.ChildNodes.FindNode( 'head' );
h.code := Node.ChildNodes.FindNode( 'xh' ).NodeValue;
h.message := Node.ChildNodes.FindNode( 'message' ).NodeValue;
Node:= TempXNode.ChildNodes.FindNode( 'body' );
if Node <> nil then
begin
p^.xh := Node.ChildNodes.FindNode( 'xh' ).NodeValue;
p^.hpzl := Node.ChildNodes.FindNode( 'hpzl' ).NodeValue;
p^.hphm := Node.ChildNodes.FindNode( 'hphm' ).NodeValue;
p^.clpp1:= Node.ChildNodes.FindNode( 'clpp1' ).NodeValue;
p^.cllx := Node.ChildNodes.FindNode( 'cllx' ).NodeValue;
end;
finally
strStream.Free;
end;
end;
end.
你也可以将他的wsdl保存成xml然后WSDL Importer导入这个xml,delphi调用webservice很简单的
使用方式就类似这样了
var
FXXX:XXX;
RIO : THTTPRIO;
rstxml:string;
yourxml:string;
begin
yourxml:='.......';
RIO:= THTTPRIO.Create( Owner );
FXXX:=RIO as XXX;
RIO.WSDLLocation:= http://10.148.223.203/PIIS.asmx?wsdl';
rstxml:=FXXX.GetValue_xml( yourxml );
end;