我需要使用一个使用WS-Security的SOAP 1.2 Web服务。我在工作中使用的平台是Delphi 10.2 Tokyo和.Net Core。这些似乎都不起作用。
在尝试使用Delphi 10.2 Tokyo的内置WSDL导入程序(将SOAP 1.2与Indy结合使用)时,发送的请求没有任何SOAP标头信息。此无效请求会引发错误对等方重置连接。
尝试使用.Net Core(使用WCF Web服务引用提供程序)时出现错误: System.PlatformNotSupportedException:'不支持TransportSecurityBindingElement.BuildChannelFactoryCore。'
大概是由于.Net Core尚不支持所需的功能:https://github.com/dotnet/wcf/blob/master/release-notes/SupportedFeatures-v2.0.0.md(不支持Security.Message)
下面是WSDL。我已从该文件中修剪了不必要的XML,并用Example替换了实际的公司名称。希望这将使您对WSDL策略/要求有足够的了解。
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:i0="http://tempuri.org/"
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="www.example.com/ExampleService"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsa10="http://www.w3.org/2005/08/addressing"
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"
xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
name="ExampleService"
targetNamespace="www.example.com/ExampleService">
<wsp:Policy wsu:Id="ExampleAPI_policy">
<wsp:ExactlyOne>
<wsp:All>
<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false" />
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256 />
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict />
</wsp:Policy>
</sp:Layout>
<sp:IncludeTimestamp />
</wsp:Policy>
</sp:TransportBinding>
<sp:EndorsingSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:SecureConversationToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:BootstrapPolicy>
<wsp:Policy>
<sp:SignedParts>
<sp:Body />
<sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing" />
<sp:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing" />
<sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing" />
<sp:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing" />
<sp:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing" />
<sp:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing" />
<sp:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing" />
</sp:SignedParts>
<sp:EncryptedParts>
<sp:Body />
</sp:EncryptedParts>
<sp:TransportBinding>
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false" />
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256 />
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict />
</wsp:Policy>
</sp:Layout>
<sp:IncludeTimestamp />
</wsp:Policy>
</sp:TransportBinding>
<sp:SignedSupportingTokens>
<wsp:Policy>
<sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:WssUsernameToken10 />
</wsp:Policy>
</sp:UsernameToken>
</wsp:Policy>
</sp:SignedSupportingTokens>
<sp:Wss11>
<wsp:Policy />
</sp:Wss11>
<sp:Trust10>
<wsp:Policy>
<sp:MustSupportIssuedTokens />
<sp:RequireClientEntropy />
<sp:RequireServerEntropy />
</wsp:Policy>
</sp:Trust10>
</wsp:Policy>
</sp:BootstrapPolicy>
</wsp:Policy>
</sp:SecureConversationToken>
</wsp:Policy>
</sp:EndorsingSupportingTokens>
<sp:Wss11 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy />
</sp:Wss11>
<sp:Trust10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:MustSupportIssuedTokens />
<sp:RequireClientEntropy />
<sp:RequireServerEntropy />
</wsp:Policy>
</sp:Trust10>
<wsaw:UsingAddressing />
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<wsp:Policy wsu:Id="ExampleAPI2_policy">
<wsp:ExactlyOne>
<wsp:All>
<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false" />
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256 />
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Lax />
</wsp:Policy>
</sp:Layout>
<sp:IncludeTimestamp />
</wsp:Policy>
</sp:TransportBinding>
<sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:WssUsernameToken10 />
</wsp:Policy>
</sp:UsernameToken>
</wsp:Policy>
</sp:SignedSupportingTokens>
<sp:Wss10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy />
</sp:Wss10>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<wsdl:types>
<!-- trimmed away types -->
</wsdl:types>
<!-- trimmed away messages -->
<wsdl:portType name="IAPIService">
<!-- trimmed away operations -->
</wsdl:portType>
<wsdl:binding name="ExampleAPI" type="tns:IAPIService">
<wsp:PolicyReference URI="#ExampleAPI_policy" />
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
<!-- trimmed away operations -->
</wsdl:binding>
<wsdl:binding name="ExampleAPI2" type="tns:IAPIService">
<wsp:PolicyReference URI="#ExampleAPI2_policy" />
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<!-- trimmed away operations -->
</wsdl:binding>
<wsdl:service name="ExampleService">
<wsdl:port name="ExampleAPI" binding="tns:ExampleAPI">
<soap12:address location="https://example.com/apps/api/APIService.svc" />
<wsa10:EndpointReference>
<wsa10:Address>https://example.com/apps/api/APIService.svc</wsa10:Address>
</wsa10:EndpointReference>
</wsdl:port>
<wsdl:port name="ExampleAPI2" binding="tns:ExampleAPI2">
<soap:address location="https://example.com/apps/api/APIService.svc/endpoint2" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
答案 0 :(得分:2)
没有特定的“最佳”平台可以使用Web服务。 但是,某些平台比其他平台更好地支持自动生成代理类。
在尝试使用Delphi 10.2 Tokyo的内置WSDL导入程序(将SOAP 1.2与Indy结合使用)时,发送的请求没有任何SOAP标头信息。
我没有使用.NET Core的经验,但是在使用Delphi 10.2时,您需要在发送请求之前手动添加(发送)SOAP标头。
这可以通过将网络服务实例投射到ISOAPHeaders
示例:
procedure TestSendHeader;
var
MyService: IMySoapWebservice;
header : TMySoapHeader;
begin
MyService := GetMySoapService();
(MyService as ISOAPHeaders).OwnsSentHeaders := True;
// Create header object
header := TMySoapHeader.Create;
// Fill header data
// header.xyz := ;
// 'Send' header with the request
(MyService as ISOAPHeaders).Send(header);
MyResponse := MyService.DoMyRequest();
end;
在发送请求之后,将OwnsSentHeaders
设置为true
将会释放所创建的标头对象。
注意:每次发出请求时,您都必须“发送”标头:
// 'Send' header with the request 1
(MyService as ISOAPHeaders).Send(header);
MyResponse := MyService.DoMyRequest1();
// 'Send' header with the request 2
(MyService as ISOAPHeaders).Send(header);
MyResponse := MyService.DoMyRequest2();
在这种情况下,请勿在完成发送请求后将OwnsSentHeaders
设置为true
并释放标题对象。
答案 1 :(得分:0)
.NET Framework完全支持SOAP服务。我已经用C#开发了一个.NET Framework应用程序,并构建了一个可以供Delphi,.NET Core等使用的DLL。这是一个a回的解决方案,但我能找到的最简单的解决方案。
使用C#访问服务:https://docs.microsoft.com/en-us/dotnet/framework/wcf/accessing-services-using-a-wcf-client
导出DLL函数:Is is possible to export functions from a C# DLL like in VS C++?