![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
SOAP, вызов метода веб сервиса [D7, WinXP]
maep © (2006-02-15 10:20:00)Начал тренероваться с SOAP.
Хочу сделать следующую вещь: есть веб сервис написанный C# с методом HelloWorld.
Есть приложение дельфи ( ну почему бы и не дельфи), которое через сокет коннектится к
веб срерверу и отправляет запрос с целью вызвать метод HelloWorld.
Делается это примерно так:
procedure TForm1.Button1Click(Sender: TObject);
var
s : string;
b : boolean;
begin
b := TcpClient1.Connect;
if not b then
begin
ShowMessage('connect failed');
exit;
end;
TcpClient1.Sendln('POST /WebSite1/Service.asmx HTTP/1.1 Host: http://localhost:1169/WebSite1/Service.asmxContent-Type: text/xml; charset=utf-8 ' +
'Content-Length: 1000 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/" /> </soap:Body> </soap:Envelope>' + #$D#$A);
ИЛИ
TcpClient1.Sendln(
'<?xml version="1.0" encoding="UTF-8" standalone="no" ?> ' +
'<SOAP:Envelope> ' +
' <SOAP:Body> ' +
' <SOAP:HelloWorld ' +
' </SOAP:HelloWorld> ' +
' </SOAP:Body> ' +
'</SOAP:Envelope> ' + #$D#$A);
TcpClient1.Close;
end;
В обоих случаях имеем
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="WebDev.WebHost"
StackTrace:
at Microsoft.VisualStudio.WebHost.Request.IsBadPath()
at Microsoft.VisualStudio.WebHost.Request.TryParseRequest()
at Microsoft.VisualStudio.WebHost.Request.Process()
at Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Connection conn)
at Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Connection conn)
at Microsoft.VisualStudio.WebHost.Server.OnSocketAccept(Object acceptedSocket)
at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
Помогите пожалуйста разобраться с этим делом..
тестовая страничка микрософт пишет что надо делать так:
SOAP 1.1
The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.
POST /WebSite1/Service.asmx HTTP/1.1
Host: localhost
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/" />
</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>
msi (2006-03-28 11:31:00) [1]А зачем так извращаться?
Я сейчас занимаюсь подобной проблемой.
В Делфи есть визард для создания прокси класса (WSDL Importer), полученный прокси клас объявляет интерфейс который можно использовать в клиенте, делается все очень просто.