Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Calling a webservice from T-SQL (failing)


Calling a webservice from T-SQL (failing)

Author
Message
Peter Gadsby
Peter Gadsby
SSC-Enthusiastic
SSC-Enthusiastic (138 reputation)SSC-Enthusiastic (138 reputation)SSC-Enthusiastic (138 reputation)SSC-Enthusiastic (138 reputation)SSC-Enthusiastic (138 reputation)SSC-Enthusiastic (138 reputation)SSC-Enthusiastic (138 reputation)SSC-Enthusiastic (138 reputation)

Group: General Forum Members
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
jcboyer-1091017
jcboyer-1091017
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 57
Did you solve your problem? I am faced with something similar and I am not finding solution(s).

Jerome
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search