c#webserviceHelloWorld测试
若要使用 HTTP POST 协议对操作进行测试,请单击“调用”按钮。
参数 值
test:
SOAP 1.1
以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。POST /HandlePatient.asmx HTTP/1.1
Host: 192.168.33.238
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/HelloWorld"<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<HelloWorld xmlns="http://tempuri.org/">
<test>string</test>
</HelloWorld>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<HelloWorldResponse xmlns="http://tempuri.org/">
<HelloWorldResult>string</HelloWorldResult>
</HelloWorldResponse>
</soap:Body>
</soap:Envelope>
SOAP 1.2
以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。POST /HandlePatient.asmx HTTP/1.1
Host: 192.168.33.238
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<HelloWorld xmlns="http://tempuri.org/">
<test>string</test>
</HelloWorld>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<HelloWorldResponse xmlns="http://tempuri.org/">
<HelloWorldResult>string</HelloWorldResult>
</HelloWorldResponse>
</soap12:Body>
</soap12:Envelope>
HTTP GET
以下是 HTTP GET 请求和响应示例。所显示的占位符需替换为实际值。GET /HandlePatient.asmx/HelloWorld?test=string HTTP/1.1
Host: 192.168.33.238HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">string</string>
HTTP POST
以下是 HTTP POST 请求和响应示例。所显示的占位符需替换为实际值。POST /HandlePatient.asmx/HelloWorld HTTP/1.1
Host: 192.168.33.238
Content-Type: application/x-www-form-urlencoded
Content-Length: lengthtest=string
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">string</string>delphi代码procedure TForm1.Button1Click(Sender: TObject);
var
url,inxml,outxml,ErrorMsg,Trade_Id:string;
xmlHttp:Olevariant;
xmldoc:Olevariant;
i,rtrn_code:integer;
doc:IXMLDocument;
node,rootnode:IXMLNODE;
params:string;
xml:TStringStream;
begin
//Trade_Id:='getHospitalInfo';
//url:='http://127.0.0.1:8082/doReqToHis?service=getHospitalInfo';
// inxml:='<?xml version="1.0" encoding="UTF-8"?> '
// +'<request op="HelloWorld">' //接口编号
// +'<aa>00011</aa></request>';
url:=Edit1.Text;
inxml:=Memo1.Text;
try
xmlHttp:=CreateOleObject('MSXML2.XMLHTTP'); //IE的版本不能低于6.0
xmldoc:=CreateOleObject('MSXML.DOMDocument');// 要对对方确定XML的组件的版本
except
showmessage('创建XML组件失败!');
Exit;
end;
try
//调用XMLHTTP组件的方法
//xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
params := 'test='+inxml;
xmlHttp.open('POST',url,false);
xmlhttp.SetRequestHeader ('Content-Type','application/x-www-form-urlencoded');
//xmlhttp.SetRequestHeader ('Content-Type','text/xml; charset=utf-8');
xmlhttp.SetRequestHeader ('Content-Length',1000);
xmlhttp.SetRequestHeader ('Cache-Control','no-cache');
xmlHttp.SetRequestHeader ('Host',' 192.168.33.238:20012');
xmldoc.loadxml(inxml);
xmlHttp.send(params);
//延时处理
i:= 0;
while xmlHttp.readystate <> 4 do
begin
i := i+1;
if i > 10000000 then
begin
showmessage('交易失败,已经超出最大延时数!');
Exit;
end;
end;
//获取交易状态码
rtrn_code := xmlHttp.status;
If rtrn_code = 12029 Then
begin
showmessage('服务未启动!');
Exit;
end
else
If rtrn_code = 500 Then
begin
showmessage('内部服务器错误,请重试!');
Exit;
end
else
If rtrn_code <> 200 Then
begin
showmessage('交易执行失败!错误代码|'+inttostr(rtrn_code));
Exit;
end;
//正常交易下的结果
outxml:= xmlHttp.responsetext;
Memo2.Lines.Add(outxml);
finally
xmlHttp := Unassigned;
xmldoc := Unassigned;
end;
end;
在send的时候报
访问无参数的是没有问题的,就是带参数的不知道怎么访问
若要使用 HTTP POST 协议对操作进行测试,请单击“调用”按钮。
参数 值
test:
SOAP 1.1
以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。POST /HandlePatient.asmx HTTP/1.1
Host: 192.168.33.238
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/HelloWorld"<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<HelloWorld xmlns="http://tempuri.org/">
<test>string</test>
</HelloWorld>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<HelloWorldResponse xmlns="http://tempuri.org/">
<HelloWorldResult>string</HelloWorldResult>
</HelloWorldResponse>
</soap:Body>
</soap:Envelope>
SOAP 1.2
以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。POST /HandlePatient.asmx HTTP/1.1
Host: 192.168.33.238
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<HelloWorld xmlns="http://tempuri.org/">
<test>string</test>
</HelloWorld>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<HelloWorldResponse xmlns="http://tempuri.org/">
<HelloWorldResult>string</HelloWorldResult>
</HelloWorldResponse>
</soap12:Body>
</soap12:Envelope>
HTTP GET
以下是 HTTP GET 请求和响应示例。所显示的占位符需替换为实际值。GET /HandlePatient.asmx/HelloWorld?test=string HTTP/1.1
Host: 192.168.33.238HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">string</string>
HTTP POST
以下是 HTTP POST 请求和响应示例。所显示的占位符需替换为实际值。POST /HandlePatient.asmx/HelloWorld HTTP/1.1
Host: 192.168.33.238
Content-Type: application/x-www-form-urlencoded
Content-Length: lengthtest=string
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">string</string>delphi代码procedure TForm1.Button1Click(Sender: TObject);
var
url,inxml,outxml,ErrorMsg,Trade_Id:string;
xmlHttp:Olevariant;
xmldoc:Olevariant;
i,rtrn_code:integer;
doc:IXMLDocument;
node,rootnode:IXMLNODE;
params:string;
xml:TStringStream;
begin
//Trade_Id:='getHospitalInfo';
//url:='http://127.0.0.1:8082/doReqToHis?service=getHospitalInfo';
// inxml:='<?xml version="1.0" encoding="UTF-8"?> '
// +'<request op="HelloWorld">' //接口编号
// +'<aa>00011</aa></request>';
url:=Edit1.Text;
inxml:=Memo1.Text;
try
xmlHttp:=CreateOleObject('MSXML2.XMLHTTP'); //IE的版本不能低于6.0
xmldoc:=CreateOleObject('MSXML.DOMDocument');// 要对对方确定XML的组件的版本
except
showmessage('创建XML组件失败!');
Exit;
end;
try
//调用XMLHTTP组件的方法
//xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
params := 'test='+inxml;
xmlHttp.open('POST',url,false);
xmlhttp.SetRequestHeader ('Content-Type','application/x-www-form-urlencoded');
//xmlhttp.SetRequestHeader ('Content-Type','text/xml; charset=utf-8');
xmlhttp.SetRequestHeader ('Content-Length',1000);
xmlhttp.SetRequestHeader ('Cache-Control','no-cache');
xmlHttp.SetRequestHeader ('Host',' 192.168.33.238:20012');
xmldoc.loadxml(inxml);
xmlHttp.send(params);
//延时处理
i:= 0;
while xmlHttp.readystate <> 4 do
begin
i := i+1;
if i > 10000000 then
begin
showmessage('交易失败,已经超出最大延时数!');
Exit;
end;
end;
//获取交易状态码
rtrn_code := xmlHttp.status;
If rtrn_code = 12029 Then
begin
showmessage('服务未启动!');
Exit;
end
else
If rtrn_code = 500 Then
begin
showmessage('内部服务器错误,请重试!');
Exit;
end
else
If rtrn_code <> 200 Then
begin
showmessage('交易执行失败!错误代码|'+inttostr(rtrn_code));
Exit;
end;
//正常交易下的结果
outxml:= xmlHttp.responsetext;
Memo2.Lines.Add(outxml);
finally
xmlHttp := Unassigned;
xmldoc := Unassigned;
end;
end;
在send的时候报
访问无参数的是没有问题的,就是带参数的不知道怎么访问
解决方案 »
- 怎么让DBgrid不能插入记录,但是能修改记录?
- 连接恢复的问题
- 关于DBGRIDEH的问题
- 请问哪儿有比较好的播放器原码哟.我有若干个问题要问,请大家进来吧,请大家帮帮忙.
- 急!!!!我在把一张临时表中的所有数据(不多)插入的另一张表时出错了,谁知道原因啊?
- 为什么我把可执行文件改名后,在任务栏上显示不一样呢?
- 在stringgrid控件里怎么输入字符?
- 300分求进销存、酒店管理等代码, [email protected]
- Delphi园地又有新东西了...
- com问题,急!
- DELPHI实现消息推送:个推C语言的DLL如何在DELPHI7中调用,我想知道如何转换,谢谢!以下是C的原形声明。
- DELPHI Tcombobox 子项中怎样添加按钮或其它控件
var URL:String;
begin
try
URL:=《这里写webservice的URL,建议写成从数据库里取的》;
mHttpRIO_ds:=THTTPRIO.Create(nil); mHttpRIO_ds.WSDLLocation:=URL+'?WSDL';
mHttpRIO_ds.URL:=URL;
mHttpRIO_ds.Port:='DsWebServiceSoap';
mHttpRIO_ds.Service:='DsWebService';
mHttpRIO_ds.HTTPWebNode.UseUTF8InHeader:=true;
InvRegistry.RegisterInvokeOptions(TypeInfo(DsWebServiceSoap),ioDocument );//就是这一行
mServiceSoap_Ds:=mHttpRIO_ds as DsWebServiceSoap;
except
on E:Exception do
begin
ShowMessage(e.Message);
exit;
end;
end;
end;然后呢,在使用的界面上 private
mServiceSoap_Ds:DsWebServiceSoap;
mHttpRIO_ds:THTTPRIO;
声明俩这玩意然后具体调用的地方
getwebservice_ds;
XML:=mServiceSoap_Ds.LoadAllCompany《webservice里头的方法名字》(_s《XML文本》);
返回值就在XML变量里头了……方法2 :在调用的方法那儿声明一个变量比喻
aa:DsWebServiceSoap;
在方法里头
aa:=GetDsWebServiceSoap《这是你webservice里头自动生成的那个public方法名字》(false,《webservice地址,以.asmx结尾的那个》);
XML:=aa.LoadAllCompany《webservice里头的方法名字》(str《XML文本》);
这样啊……post的方式我还真没玩过……