您的位置:首页 > 数据库

SQL 2005中用存储过程调用Web Services

2007-10-31 12:11 459 查看
转贴

SQL 2000中还未找到解决办法,但是因为SQL 2005本身就是在.Net架构上,所以支持存储过程中调用WSE

CLR procedure in SQL2K5 calling webservice

Posted by: Ludo Bernaerts on ?? 24, 2006 DIGG
function _parseDiggURL() {
var _diggURL = "http://digg.com/submit?phase=2&topic=Programming&url="
_diggURL += encodeURIComponent(location.href);
_diggURL += "&title=";
_diggURL += escape ( "CLR procedure in SQL2K5 calling webservice") ;
_diggURL += "&bodytext=";
_diggURL += escape ( "Hi, I want to create following procedure to call a webservice. build ok execution not ok.<br>When i do it in a seperated program it works. in the clr procedure not.<br>It always end with 'System.InvalidOperationException' occurred in System.Xml.dll<br><br>Can some one help me.<br>Ludo<br><br>SQL code: <br>exec dbo.SendStatusToWebservice 'SQL2K5','TEST Ludo','GREEN'<br><br>.Net code<br>using System;<br>using System.Data;<br>using System.Data.Sql;<br>using System.Data.SqlTypes;<br>using System.Data.SqlClient;<br>using Microsoft.SqlServer.Server;<br>using System.Diagnostics;<br><br>public partial class CLR_Procedures<br>{<br> [Microsoft.SqlServer.Server.SqlProcedure]<br><br> }<br>    public static void SendStatusToWebservice(SqlString MyAppl, SqlString MyMessage, SqlString MyStatus)<br>    {<br>     string log;<br>        // Connect to webservice and add logging to it<br>        SQL_UDP.bgc.wss.Library wlib = new SQL_UDP.bgc.wss.Library();<br><br>        wlib.Credentials = System.Net.CredentialCache.DefaultCredentials;<br><br>        log = wlib.WSScreateLog(MyAppl.Value);<br>        wlib.WSSwriteLog(log, MyMessage.Value);// + " at @ " + DateTime.Now.ToString);<br>        wlib.SetBatchStatus(MyStatus.Value, log);<br>    }<br>};<br><br>Debug result:<br>Auto-attach to process '[3068] [SQL] bgc-mikmxeue486' on machine 'bgc-mikmxeue486' succeeded.<br>Debugging script from project script file.<br><br>The thread 'bgc-mikmxeue486 [61]' (0xd60) has exited with code 0 (0x0).<br>The thread 'bgc-mikmxeue486 [61]' (0xd60) has exited with code 0 (0x0).<br>The thread 'bgc-mikmxeue486 [61]' (0xd60) has exited with code 0 (0x0).<br>'sqlservr.exe' (Managed): Loaded 'C:\WINNT\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br>Auto-attach to process '[3068] sqlservr.exe' on machine 'bgc-mikmxeue486' succeeded.<br>'sqlservr.exe' (Managed): Loaded 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\SqlAccess.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br>'sqlservr.exe' (Managed): Loaded 'C:\WINNT\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br>'sqlservr.exe' (Managed): Loaded 'C:\WINNT\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br>'sqlservr.exe' (Managed): Loaded 'C:\WINNT\assembly\GAC_32\System.Transactions\2.0.0.0__b77a5c561934e089\System.Transactions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br>'sqlservr.exe' (Managed): Loaded 'C:\WINNT\assembly\GAC_MSIL\System.Security\2.0.0.0__b03f5f7f11d50a3a\System.Security.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br>'sqlservr.exe' (Managed): Loaded 'C:\WINNT\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br>'sqlservr.exe' (Managed): Loaded 'SQL_UDP', No symbols loaded.<br>'sqlservr.exe' (Managed): Loaded 'C:\WINNT\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll', No symbols loaded.<br>'sqlservr.exe' (Managed): Loaded 'C:\WINNT\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', No symbols loaded.<br>'sqlservr.exe' (Managed): Loaded 'WebserviceCLR', Symbols loaded.<br>A .NET Framework error occurred during execution of user defined routine or aggregate 'CallWebservice': <br>System.InvalidOperationException: Cannot load dynamically generated serialization assembly. In some hosting environments assembly load functionality is restricted, consider using pre-generated serializer. Please see inner exception for more information. ---> System.IO.FileLoadException: LoadFrom(), LoadFile(), Load(byte[]) and LoadModule() have been disabled by the host.<br>System.IO.FileLoadException: <br>   at System.Reflection.Assembly.nLoadImage(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark, Boolean fIntrospection)<br>   at System.Reflection.Assembly.Load(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence securityEvidence)<br>   at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames)<br>   at Microsoft.CSharp.CSharpCodeGenerator.FromSourceBatch(CompilerParameters options, String[] sources)<br>   at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromSourceBatch(CompilerParameters options, String[] sources)<br>   at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromSource(CompilerParameter<br> ...<br>System.InvalidOperationException: <br>   at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, CompilerParameters parameters, Evidence evidence)<br>   at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, CompilerParameters parameters, Assembly assembly, Hashtable assemblies)<br>   at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)<br>   at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)<br>   at System.Web.Services.Protocols.SoapClientType..ctor(Type type)<br>   at System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()<br>   at WebserviceCLR.wsslib.Library...<br>No rows affected.<br>(0 row(s) returned)<br>Finished running sp_executesql.<br>A first chance exception of type 'System.InvalidOperationException' occurred in System.Xml.dll<br>The thread 'bgc-mikmxeue486 [61]' (0xd60) has exited with code 0 (0x0).<br>The program '[3068] [SQL] bgc-mikmxeue486: bgc-mikmxeue486' has exited with code 0 (0x0).<br>The program '[3068] sqlservr.exe: Managed' has exited with code 259 (0x103).").substring(0,300);
return _diggURL ;
}

Hi, I want to create following procedure to call a webservice. build ok execution not ok.

When i do it in a seperated program it works. in the clr procedure not.

It always end with 'System.InvalidOperationException' occurred in System.Xml.dll

Can some one help me.

Ludo

SQL code:

exec dbo.SendStatusToWebservice 'SQL2K5','TEST Ludo','GREEN'

.Net code

using System;

using System.Data;

using System.Data.Sql;

using System.Data.SqlTypes;

using System.Data.SqlClient;

using Microsoft.SqlServer.Server;

using System.Diagnostics;

public partial class CLR_Procedures

{

[Microsoft.SqlServer.Server.SqlProcedure]

}

public static void SendStatusToWebservice(SqlString MyAppl, SqlString MyMessage, SqlString MyStatus)

{

string log;

// Connect to webservice and add logging to it

SQL_UDP.bgc.wss.Library wlib = new SQL_UDP.bgc.wss.Library();

wlib.Credentials = System.Net.CredentialCache.DefaultCredentials;

log = wlib.WSScreateLog(MyAppl.Value);

wlib.WSSwriteLog(log, MyMessage.Value);// + " at @ " + DateTime.Now.ToString);

wlib.SetBatchStatus(MyStatus.Value, log);

}

};

Debug result:

Auto-attach to process '[3068] [SQL] bgc-mikmxeue486' on machine 'bgc-mikmxeue486' succeeded.

Debugging script from project script file.

The thread 'bgc-mikmxeue486 [61]' (0xd60) has exited with code 0 (0x0).

The thread 'bgc-mikmxeue486 [61]' (0xd60) has exited with code 0 (0x0).

The thread 'bgc-mikmxeue486 [61]' (0xd60) has exited with code 0 (0x0).

'sqlservr.exe' (Managed): Loaded 'C:\WINNT\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

Auto-attach to process '[3068] sqlservr.exe' on machine 'bgc-mikmxeue486' succeeded.

'sqlservr.exe' (Managed): Loaded 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\SqlAccess.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'sqlservr.exe' (Managed): Loaded 'C:\WINNT\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'sqlservr.exe' (Managed): Loaded 'C:\WINNT\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'sqlservr.exe' (Managed): Loaded 'C:\WINNT\assembly\GAC_32\System.Transactions\2.0.0.0__b77a5c561934e089\System.Transactions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'sqlservr.exe' (Managed): Loaded 'C:\WINNT\assembly\GAC_MSIL\System.Security\2.0.0.0__b03f5f7f11d50a3a\System.Security.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'sqlservr.exe' (Managed): Loaded 'C:\WINNT\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'sqlservr.exe' (Managed): Loaded 'SQL_UDP', No symbols loaded.

'sqlservr.exe' (Managed): Loaded 'C:\WINNT\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll', No symbols loaded.

'sqlservr.exe' (Managed): Loaded 'C:\WINNT\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', No symbols loaded.

'sqlservr.exe' (Managed): Loaded 'WebserviceCLR', Symbols loaded.

A .NET Framework error occurred during execution of user defined routine or aggregate 'CallWebservice':

System.InvalidOperationException: Cannot load dynamically generated serialization assembly. In some hosting environments assembly load functionality is restricted, consider using pre-generated serializer. Please see inner exception for more information. ---> System.IO.FileLoadException: LoadFrom(), LoadFile(), Load(byte[]) and LoadModule() have been disabled by the host.

System.IO.FileLoadException:

at System.Reflection.Assembly.nLoadImage(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark, Boolean fIntrospection)

at System.Reflection.Assembly.Load(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence securityEvidence)

at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames)

at Microsoft.CSharp.CSharpCodeGenerator.FromSourceBatch(CompilerParameters options, String[] sources)

at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromSourceBatch(CompilerParameters options, String[] sources)

at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromSource(CompilerParameter

...

System.InvalidOperationException:

at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, CompilerParameters parameters, Evidence evidence)

at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, CompilerParameters parameters, Assembly assembly, Hashtable assemblies)

at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)

at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)

at System.Web.Services.Protocols.SoapClientType..ctor(Type type)

at System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()

at WebserviceCLR.wsslib.Library...

No rows affected.

(0 row(s) returned)

Finished running sp_executesql.

A first chance exception of type 'System.InvalidOperationException' occurred in System.Xml.dll

The thread 'bgc-mikmxeue486 [61]' (0xd60) has exited with code 0 (0x0).

The program '[3068] [SQL] bgc-mikmxeue486: bgc-mikmxeue486' has exited with code 0 (0x0).

The program '[3068] sqlservr.exe: Managed' has exited with code 259 (0x103).
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: