c#webservice
HelloWorld
測驗
若要使用 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.238
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>
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: length
test=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的時候報

訪問無引數的是沒有問題的,就是帶引數的不知道怎么訪問
uj5u.com熱心網友回復:
呼叫webservice有倆辦法方法之一找個放通用方法的datamodule,
procedure 模塊名字.getwebservice_ds;
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文本》);
uj5u.com熱心網友回復:
THTTPRIO 現在的問題是使用這個控制元件會和我們框架沖突,所以才選擇用post方式來訪問。uj5u.com熱心網友回復:
這樣啊……
post的方式我還真沒玩過……
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/84808.html
