在没有CLR的情况下从SQL调用WCF服务

时间:2015-02-06 12:05:40

标签: sql-server web-services wcf

是否可以在不使用CLR的情况下从SQL调用WCF服务? (和asmx一样)。

以下代码与asmx服务完美配合,但不适用于WCF

    --INTERNAL PARAMETERS
    DECLARE @Object AS INT
    DECLARE @ResponseText AS VARCHAR(8000)
    DECLARE @SiteURL AS VARCHAR(100) = fGetSiteUrl()

    --BUILD SERVICE URL
    DECLARE @ServiceURL VARCHAR(MAX) = @SiteURL + '/WebServices/PortalService.asmx/CreateUser'
                                        + '?userName=' + @UserName
                                        + '&password=' + @ClearTextPassword
                                        + '&question=' + @PasswordQuestion
                                        + '&answer=' + @PasswordAnswer
                                        + '&email=' + @Email

    --BUILD AND EXECUTE SERVICE CALL
    EXEC sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
    EXEC sp_OAMethod @Object, 'open', NULL, 'get',@ServiceURL, 'false'
    EXEC sp_OAMethod @Object, 'send'
    EXEC sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
    EXEC sp_OADestroy @Object

    --STRIP OUT USELESS FLUFF
    SET @ResponseText = SUBSTRING(@ResponseText, CHARINDEX('>', @ResponseText) + 1, (LEN(@ResponseText) - CHARINDEX('>', @ResponseText)))
    SET @ResponseText = SUBSTRING(@ResponseText, CHARINDEX('>', @ResponseText) + 1, (LEN(@ResponseText) - CHARINDEX('>', @ResponseText)))
    SET @ResponseText = CONCAT('<Result>', @ResponseText)

    DECLARE @MyXML XML  = @ResponseText

    --GET THE USER USERID OF THE NEW USER
    SET @UserId =   (SELECT     a.b.value('UserId[1]','nvarchar(1280)') AS UserId
                    FROM        @MyXML.nodes('Result') a(b))

0 个答案:

没有答案