Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a SP using MSXML2 to call a Web Service.
It is working on my local machine using SQL Server 2008R2
It is not working on my server, using SQL Server 2014.

Running the same MSXML2 from a Javascript program from the command line, works on both local machine and server.

The SQL Server service is running under an Admin user on both machines.

Here's the SQL:

SQL
Declare @Object as Int;
Declare @ResponseText as Varchar(8000);
Declare @Status as int;
Declare @Body as varchar(8000) =
'{"someParameterName": ["AAAAAAAA" ],"Message": "Here is a message I am sending","securityId": "DA6AC379-703F-4BCC-9B0B-8DBAF87EB5C6","type": "send_message"}'

Declare @BodyLength int = LEN(@Body)
Exec sp_OACreate 'MSXML2.ServerXMLHTTP', @Object OUT;
Exec sp_OAMethod @Object, 'setProxy', '2', 'http://localhost:8888',''
Exec sp_OAMethod @Object, 'open', NULL, 'post',
    'https://api.theUrl.com/external/TheMessageApi',
    'false'

Exec sp_OAMethod @Object, 'setRequestHeader', null, 'Content-Type', 'application/json'
Exec sp_OAMethod @Object, 'setRequestHeader', null, 'Content-LEngth', @BodyLength

Exec sp_OAMethod @Object, 'send', null , @Body


Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
Exec sp_OAMethod @Object, 'status', @status OUTPUT
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT

Select @ResponseText as Response, @Status as Status

Exec sp_OADestroy @Object


On my local machine I see the response text and status of 200
On the server I see Null, Null

I appreciate this is a bit specific - but I'm at a loss what else to look at!

I tried installing Fiddler - but that doesn't catch the traffic even when the call works!

Any advice gratefully received!
Posted
Updated 7-Jul-17 15:03pm

Well, OK , looks like I will have to answer it myself.

It turns out that the MSXML6.dll on Windows 7 is different to the MSXML6.dll on Windows Server 2012

I don't know what the difference is, but the 'send' method fails on the 2012 version with an error
Msxml6.dll 0x80070057

which means 'The parameter is incorrect'

The problem is the same with MSCML3.dll!

So - I copied over the two DLLs from Windows\System32 (from my workstation to the server) gave it a quick reboot and BINGO!

Lesson learned - I should have looked at the return codes from each call to the DLL - I would have tracked down the issue sooner!


But now I can call a web service from my SQL Server trigger, so I am a happy chappy!
 
Share this answer
 
use:
SQL
DECLARE @request varchar(max)
SET @request = 'send("' + REPLACE(@Body, '"', '''') + '")'
Exec sp_OAMethod @Object, @request

INSERT INTO @result
 EXEC sp_OAGetProperty @Object, 'responseText'
 
Share this answer
 
Comments
CHill60 14-Mar-15 10:53am    
Problem was resolved over 6 months ago - there was nothing wrong with the code it was the wrong DLL.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900