制造这个庞然大物对于我自己的需要
CREATE PROCEDURE [dbo].[RequestHttpWebService]
@Url varchar(1024),
@HttpMethod varchar(10),
@ParamsValues varchar(1024), -- param1=value¶m2=value
@SoapAction varchar(1024) = null
AS BEGIN SET NOCOUNT ON;
--set @Url = 'http://localhost/service.asmx'
--set @HttpMethod = 'soap'
--set @ParamsValues = 'login=tr2280&password=Qwe12345&domain=webtech.development'
--set @SoapAction = 'Authenticate'
if @HttpMethod in ('get','GET') and len(@ParamsValues) > 0
begin
set @Url = @Url + '?' + @ParamsValues
end
declare @obj int
,@response varchar(8000)
,@responseXml xml
,@status varchar(50)
,@statusText varchar(1024)
,@method varchar(10) = (case when @HttpMethod in ('soap','SOAP') then 'POST' else @HttpMethod end)
exec sp_OACreate 'MSXML2.ServerXMLHttp', @obj out
exec sp_OAMethod @obj, 'Open', null, @method, @Url, false
if @HttpMethod in ('get','GET')
begin
exec sp_OAMethod @obj, 'send'
end
else if @HttpMethod in ('post','POST')
begin
exec sp_OAMethod @obj, 'setRequestHeader', null, 'Content-Type', 'application/x-www-form-urlencoded'
exec sp_OAMethod @obj, 'send', null, @ParamsValues
end
else if @HttpMethod in ('soap','SOAP')
begin
if @SoapAction is null
raiserror('@SoapAction is null', 10, 1)
declare @host varchar(1024) = @Url
if @host like 'http://%'
set @host = right(@host, len(@host) - 7)
else if @host like 'https://%'
set @host = right(@host, len(@host) - 8)
if charindex(':', @host) > 0 and charindex(':', @host) < charindex('/', @host)
set @host = left(@host, charindex(':', @host) - 1)
else
set @host = left(@host, charindex('/', @host) - 1)
declare @envelope varchar(8000) = '<?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><{action} xmlns="http://tempuri.org/">{params}</{action}></soap:Body></soap:Envelope>'
declare @params varchar(8000) = ''
WHILE LEN(@ParamsValues) > 0
BEGIN
declare @param varchar(256),
@value varchar(256)
IF charindex('&', @ParamsValues) > 0
BEGIN
SET @param = left(@ParamsValues, charindex('&', @ParamsValues) - 1)
set @value = RIGHT(@param, len(@param) - charindex('=', @param))
set @param = left(@param, charindex('=', @param) - 1)
set @params = @params + '<' + @param + '>' + @value + '</'+ @param + '>'
SET @ParamsValues = right(@ParamsValues, LEN(@ParamsValues) - LEN(@param + '=' + @value + '&'))
END
ELSE
BEGIN
set @value = RIGHT(@ParamsValues, len(@ParamsValues) - charindex('=', @ParamsValues))
set @param = left(@ParamsValues, charindex('=', @ParamsValues) - 1)
set @params = @params + '<' + @param + '>' + @value + '</'+ @param + '>'
SET @ParamsValues = NULL
END
END
set @envelope = replace(@envelope, '{action}', @SoapAction)
set @envelope = replace(@envelope, '{params}', @params)
set @SoapAction = 'http://tempuri.org/' + @SoapAction
print @host
print @SoapAction
print @envelope
exec sp_OAMethod @obj, 'setRequestHeader', null, 'Content-Type', 'text/xml; charset=utf-8'
exec sp_OAMethod @obj, 'setRequestHeader', null, 'Host', @host
exec sp_OAMethod @obj, 'setRequestHeader', null, 'SOAPAction', @SoapAction
exec sp_OAMethod @obj, 'send', null, @envelope
end
exec sp_OAGetProperty @obj, 'responseText', @response out
exec sp_OADestroy @obj
select @status as [status], @statusText as [statusText], @response as [response]
END
GO
你得到一个解决方案吗?我目前处于完全相同的情况 – 2015-06-17 13:57:58