我正在尝试使用 OLE 自动化存储过程从 SQL Server 调用 SOAP Web 服务,但我遇到了 Content-Encoding gzip 响应问题。
当使用 SOAP UI 测试方法时,它就像一个魅力。
Soap UI 显示类似 xml 的响应。Http 日志显示响应是 gzip 编码的
当我从 SQL Server 拨打电话时,我收到了这样的意外响应
状态返回正常 200。
GetAllResponseHeaders
不包含“内容编码:gzip”,Soap UI 包含!我包括了显示在 SOAP UI 上的所有请求标头。
这是我的代码(为了便于阅读,我省略了错误处理)
DECLARE
@URI varchar(2000) = 'http://foo/foo.wsdl',
@methodName varchar(50) = 'post',
@requestBody varchar(8000) = '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:CCTwebservices"><soapenv:Header/><soapenv:Body><urn:recepcionLiberacionTatc soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><user xsi:type="xsd:string">foo</user><password xsi:type="xsd:string">foo</password><dataIn xsi:type="xsd:string"><![CDATA[foo]]></dataIn></urn:recepcionLiberacionTatc></soapenv:Body></soapenv:Envelope>',
@SoapAction varchar(255) = 'urn:CCTwebservices#recepcionLiberacionTatc',
@responseText varchar(8000);
DECLARE @objectID int
DECLARE @hResult int
DECLARE @source varchar(255), @desc varchar(255)
--create object
EXEC @hResult = sp_OACreate 'MSXML2.ServerXMLHTTP', @objectID OUT
-- open the destination URI with Specified method
EXEC @hResult = sp_OAMethod @objectID, 'open', null, @methodName, @URI, 'false', null, null
-- set request headers
EXEC @hResult = sp_OAMethod @objectID, 'setRequestHeader', null, 'Content-Type', 'text/xml;charset=UTF-8'
EXEC @hResult = sp_OAMethod @objectID, 'setRequestHeader', null, 'Accept-Encoding', 'gzip,deflate'
EXEC @hResult = sp_OAMethod @objectID, 'setRequestHeader', null, 'Host', 'ws.foo`enter code here`.cl'
EXEC @hResult = sp_OAMethod @objectID, 'setRequestHeader', null, 'Connection', 'Keep-Alive'
EXEC @hResult = sp_OAMethod @objectID, 'setRequestHeader', null, 'SOAPAction', @SoapAction
declare @len int
set @len = len(@requestBody)
EXEC @hResult = sp_OAMethod @objectID, 'setRequestHeader', null, 'Content-Length', @len
-- send the request
EXEC @hResult = sp_OAMethod @objectID, 'send', null, @requestBody
EXEC @hResult = sp_OAMethod @objectID, 'getResponseHeader', null, 'Content-Encoding' -- Return null
EXEC @hResult = sp_OAMethod @objectID, 'GetAllResponseHeaders' -- Response doesn't incluye 'Content-Encoding: gzip', Soap UI does!.
exec sp_OAGetProperty @objectID, 'StatusText'
exec sp_OAGetProperty @objectID, 'Status'
exec sp_OAGetProperty @objectID, 'responseText' -- return the xml show previosly
exec sp_OADestroy @objectID
有什么帮助来完成这项工作吗?