December 15, 2011 at 10:32 am
hi,
I am trying to create a CLR stored procedure to call an external webservice, with very little success!!!
I have created a test c# component that uses the webservice fine. When I create a CLR class I get an error
Msg 6522, Level 16, State 1, Procedure VALIDATE_ACCOUNT, Line 0
A .NET Framework error occurred during execution of user-defined routine or aggregate "VALIDATE_ACCOUNT":
System.InvalidOperationException: Could not find default endpoint element that references contract 'ServiceReference1.validateSoap' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
System.InvalidOperationException:
at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
at System.ServiceModel.EndpointTrait`1.CreateChannelFactory()
at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
at System.ServiceModel.ClientBase`1..ctor()
at ValidateFinancialDetails.ServiceReference1.validateSoapClient..ctor()
at ValidateFinancialDetails.BaseFunctionClass.ValidateAccount(SqlString strSortCode, SqlString strAccountCode, SqlString& strResult)
.
I have setup the CLR component as follows:-
using System;
//using System.Collections.Generic;
//using System.Text;
//using System.IO;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using Microsoft.SqlServer.Server;
using System.Net;
namespace ValidateFinancialDetails
{
public class BaseFunctionClass
{
#region "Default Constructor"
public BaseFunctionClass()
{
}
#endregion
#region "Welcome Function"
[SqlProcedure]
public static void ValidateAccount(SqlString strSortCode,SqlString strAccountCode,out SqlString
strResult)
{
string SortCode = Convert.ToString(strSortCode);
string AccountCode = Convert.ToString(strAccountCode);
bool AuthRequired = false;
// Try default credentials (e.g. for ISA with NTLM integration)
//WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
WebRequest.DefaultWebProxy.Credentials = new NetworkCredential("xxxx", "xxxx", "xxxx");
AuthRequired = false;// Assume this will allow us to connect for now
string keycode = "";
ServiceReference1.validateSoapClient sc = new ServiceReference1.validateSoapClient();
//ServiceReference1.validateAccountRequest AccObj = new ServiceReference1.validateAccountRequest();
//ServiceReference1.paccnum pp = new ServiceReference1.paccnum();
//pp = sc.validateAccount(keycode, SortCode, AccountCode, "", "", "GB", "");
//strResult = pp.validity.ToString();
strResult = "WIBBLE";
}
#endregion
}
}
The setup in SQL server is as follows:-
ALTER DATABASE H21_STAGING SET TRUSTWORTHY ON
GO
CREATE ASSEMBLY ValidateFinancialDetails
AUTHORIZATION dbo
FROM 'C:\Projects\CSHARP\ValidateFinancialDetails\ValidateFinancialDetails\bin\Debug\ValidateFinancialDetails.dll'
WITH PERMISSION_SET = UNSAFE
GO
CREATE PROCEDURE VALIDATE_ACCOUNT
(
@SORT_CODE NVARCHAR(255),
@ACCOUNT_CODE NVARCHAR(255),
@OUTPUT NVARCHAR(MAX) OUTPUT
)
AS EXTERNAL NAME ValidateFinancialDetails.[ValidateFinancialDetails.BaseFunctionClass].ValidateAccount
GO
I run it as follows:-
DECLARE @a NVARCHAR(255)
EXEC VALIDATE_ACCOUNT '123','123',@A OUTPUT
print @a
Any help very much appreciated.
Thanks
Peter Gadsby
0777 6090490
Peter Gadsby
Business Intelligence Consultant
www.hgconsult.co.uk
January 28, 2012 at 9:58 am
Did you solve your problem? I am faced with something similar and I am not finding solution(s).
Jerome
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply