Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Calling a webservice from T-SQL (failing) Expand / Collapse
Author
Message
Posted Thursday, December 15, 2011 10:32 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, June 11, 2013 9:11 AM
Points: 138, Visits: 305
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
Post #1222624
Posted Saturday, January 28, 2012 9:58 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, March 3, 2014 4:39 AM
Points: 6, Visits: 49
Did you solve your problem? I am faced with something similar and I am not finding solution(s).

Jerome
Post #1243228
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse