我自己的 SOAP 代码?

发布于 2024-12-17 05:39:51 字数 934 浏览 1 评论 0原文

D6 教授

我们必须使用 SOAP XML 服务。 我尝试导入wsdl,并使用Delphi生成的界面,但失败。

而且:正如我所见,我必须在 XML 部分中提供用户名和密码,但我不知道如何使用此自动界面...

我确定我手动提供 XML。 这不是问题,问题是如何发布到服务器...... wsdl import 知道如何调用服务器。它知道网址、端口等。

我想编写自己的代码。我认为 SOAP 调用是使用“Post”方法,我可以轻松做到这一点。 但是post需要什么参数呢? SOAP服务器读取哪些参数?

要理解我所说的内容,请参阅此代码(FParams : TStrings):

procedure TDDHTTPObject.Post;
var
    WinHttpReq : variant;
    posts : string;
begin
    Result := '';
    WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
    try
        posts := EncodeParamsToURL(FParams);
        URL := URL + '?' + posts;
        WinHttpReq.Open('POST', URL, false);
        WinHttpReq.Send();
        Result := WinHttpReq.ResponseText;
    finally
        WinHttpReq := 0;
    end;
end;

例如:

Params['data'] = xmlstring;

Params['soap'] = xmlstring;

你知道一些关于它的事情吗?

D6 prof.

We must use a SOAP XML service.
I tried to import wsdl, and use the interface generated by Delphi, but it is failed.

And: as I see I must provide username and password in an XML section, but I don't know how to do with this automatic interface...

I determined that I provide the XML by hand.
It is not problem, the problem is how to post into server...
The wsdl import knows how to call the server. It is know the url, port, etc.

I want to write my own code. As I think SOAP calls are uses "Post" method what I can do easily.
But what parameter is needed for post?
Which parameters is what read by SOAP server?

To understand what I talking about it, see this code (FParams : TStrings):

procedure TDDHTTPObject.Post;
var
    WinHttpReq : variant;
    posts : string;
begin
    Result := '';
    WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
    try
        posts := EncodeParamsToURL(FParams);
        URL := URL + '?' + posts;
        WinHttpReq.Open('POST', URL, false);
        WinHttpReq.Send();
        Result := WinHttpReq.ResponseText;
    finally
        WinHttpReq := 0;
    end;
end;

For example:

Params['data'] = xmlstring;

or

Params['soap'] = xmlstring;

Do you know something about it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

靑春怀旧 2024-12-24 05:39:52

如果您使用 .NET 作为 Web 服务器,当您浏览到 WS URL 时,您可以看到方法和原始 XML,即:
http://yourdomain.com/ws/ApplicationWebService.asmx

XML 可用于 SOAP 1.1和1.2
它可能看起来像这样(SOAP 1.1):

<?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:Header>
    <UserIdentificationHeader xmlns="http://yourdomain.com/ws">
      <UserAgent>string</UserAgent>
      <UserToken>string</UserToken>
    </UserIdentificationHeader>
  </soap:Header>
  <soap:Body>
    <MyTestMethod xmlns="http://yourdomain.com/ws" />
  </soap:Body>
</soap:Envelope>

接下来我使用“MSXML2.XMLHTTP”,如下所示:

var
  mhttp: OleVariant;

URL := 'http://yourdomain.com/ws/ApplicationWebService.asmx';
mhttp := CreateOleObject('MSXML2.XMLHTTP');
mhttp.Open('POST', URL, False);  // False=synchronously
mhttp.setRequestHeader('User-Agent', APP_WS_USER_AGENT); // optional
mhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
mhttp.setRequestHeader('SoapAction', 'http://yourdomain.com/ws/' + 'MyTestMethod');

mhttp.send(TheSOAPXML);

if mhttp.Status = 202 then ShowMessage('ACCEPTED OK!');

If you use .NET as your web server you can see the Methods and raw XML when you browse to the WS URL ie:
http://yourdomain.com/ws/ApplicationWebService.asmx

the XML is available for both SOAP 1.1 and 1.2
and it may look like this (SOAP 1.1):

<?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:Header>
    <UserIdentificationHeader xmlns="http://yourdomain.com/ws">
      <UserAgent>string</UserAgent>
      <UserToken>string</UserToken>
    </UserIdentificationHeader>
  </soap:Header>
  <soap:Body>
    <MyTestMethod xmlns="http://yourdomain.com/ws" />
  </soap:Body>
</soap:Envelope>

Next I use "MSXML2.XMLHTTP" like this:

var
  mhttp: OleVariant;

URL := 'http://yourdomain.com/ws/ApplicationWebService.asmx';
mhttp := CreateOleObject('MSXML2.XMLHTTP');
mhttp.Open('POST', URL, False);  // False=synchronously
mhttp.setRequestHeader('User-Agent', APP_WS_USER_AGENT); // optional
mhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
mhttp.setRequestHeader('SoapAction', 'http://yourdomain.com/ws/' + 'MyTestMethod');

mhttp.send(TheSOAPXML);

if mhttp.Status = 202 then ShowMessage('ACCEPTED OK!');
哆兒滾 2024-12-24 05:39:52

实例化您自己的 THttpRio 组件并将其传递给 Web 服务调用。使用 THttpRio.BeforeExecute 事件在将 SOAPRequest 流发送到服务之前对其进行修改。那里有很多例子,但看看 THttprio onBeforeExecute 更改soapRequest作为一个可以帮助你的例子去。

Instantiate your own THttpRio component and pass it in to the web service call. Use the THttpRio.BeforeExecute event to modify the SOAPRequest stream before it gets sent to the service. Lots of examples out there but look at THttprio onBeforeExecute changing the soapRequest as one to get you going.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文