問題描述
我有一個帶有 Web 方法的 Web 服務,該方法可以響應您傳遞的任何內容.
I have a web service with a web method which echoes whatever you pass it.
我嘗試從 T-SQL 代碼調用我的 Web 方法,但它既不工作也不產生任何異常或錯誤.
I try to call my web method from T-SQL code but it neither works nor yields any exception or error.
代碼如下:
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO
Declare @Object as Int;
Declare @ResponseText as Varchar(8000);
Exec sp_OACreate 'MSXML2.ServerXMLHTTP', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'get',
'http://vserver250:8600/EcomSmsSvc.asmx/Reply?message=hi','false'
Exec sp_OAMethod @Object, 'send'
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
Select @ResponseText
Exec sp_OADestroy @Object
我的網絡服務工作正常,當我通過網絡瀏覽器調用它時,它返回我發送的消息,但是當我從 T-SQL 調用它時,結果總是 NULL
.
My web service works fine, and when I call it through web browsers it returns the message I send it, but when I call it from T-SQL the result is always NULL
.
誰能幫我找出問題所在?
Can anyone help me find out where the problem is?
推薦答案
我建議使用 內置于 .NET 的網絡服務客戶端.我想這將是一個更簡潔的解決方案,更易于維護且更易于測試和調試.
I would suggest to do it using a web service client built in .NET. I suppose this would be a cleaner solution, more maintainable and easier to test and debug.
在這篇文章中你可以找到這樣一個例子.
In this post you could find such an example.
希望我有所幫助!
這篇關于從 SQL Server 調用 Web 服務的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!