Showing posts with label webservice. Show all posts
Showing posts with label webservice. Show all posts

Sunday, March 25, 2012

accessing external webservice or webpage from SQL 2005

Is it possible to access a webservice from within SQL 2005?

What I am looking to do is place a trigger on a specific table, and detect if a specific column is being updated. If it is, I want to launch a robust process that does x, y and z. Something like this:

1) record is updated indicating that an account is closed.

2) SQL launched a webservice/ aspx page that builds an HTML email template and then mail it.

thanks!

SQL Server 2005 does have XML web service support. Seehttp://msdn2.microsoft.com/en-us/library/ms191274.aspx.|||

Wow, thanks for the speedy reply. The documentation behind the link you sent seems to refer to SQL server fielding SOAP requests and "listening" to and delivering data, where the SQL server is processing the request.

But is the opposite possible? SQL calling another webservice?

Thursday, March 22, 2012

Accessing a web service using clr in SQL 2005

I need to access a billing webservice from SQL. I createde a new c# class project and made a web refrence to the web service "ProdBilling".

Here is the code of my assembly

using System.Data;
using Microsoft.SqlServer.Server;
using System.Data.SqlTypes;
namespace PaymentProc
{
public class PaymentProc
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void ChargeCard(int account, int amount)
{
string Response;
ProdBilling.Service serv = new ProdBilling.Service();
Response = serv.ChargeCard(account, amount);
SqlContext.Pipe.Send(Response);
}
}
}

I then ran WSDL

wsdl /oStick out tongueaymentProc.cs /nStick out tongueaymentProc http://ProdWeb1/PaymentProc/PaymentProc.asmx

Then compliled

csc /target:library PaymentProc.cs

and added the assembly
CREATE ASSEMBLY PaymentProc from 'D:\ProdCode\PaymentProc.dll' WITH
PERMISSION_SET = UNSAFE

I cannot figure out how to refrence the chargecard method

I have tried

CREATE PROCEDURE PaymentProc
@.Account int,
@.Amount int
AS
EXTERNAL NAME PaymentProc.[PaymentProc.PaymentProc].ChargeCard

It seems wsdl.exe put all this serialization code

namespace PaymentProc {
using System.Diagnostics;
using System.Web.Services;
using System.ComponentModel;
using System.Web.Services.Protocols;
using System;
using System.Xml.Serialization;

///
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="ServiceSoap", Namespace="http://ProdWeb1/PaymentProc")]
public partial class PaymentProc : System.Web.Services.Protocols.SoapHttpClientProtocol {

private System.Threading.SendOrPostCallback ChargeCardOperationCompleted;

///
public PaymentProc()
{
this.Url = "http://ProdWeb1/PaymentProc/PaymentProc.asmx";
}

///
public event ChargeCardCompletedEventHandler ChargeCardCompleted;

///
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://ProdWeb1/PaymentProc/ChargeCard", RequestNamespace="http://ProdWeb1/PaymentProc", ResponseNamespace="http://ProdWeb1/PaymentProc", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string ChargeCard(int account, int amount) {
object[] results = this.Invoke("ChargeCard", new object[] {
account,
amount});
return ((string)(results[0]));
}
.................

When I run

CREATE PROCEDURE PaymentProc
@.Account int,
@.Amount int
AS
EXTERNAL NAME PaymentProc.[PaymentProc.PaymentProc].ChargeCard

I get error

Method, property or field 'ChargeCard' of class 'PaymentProc.PaymentProc' in assembly 'PaymentProc' is not static.

Any ideas? This seemsed so straitforward in the beginning.

Change your ChargeCard CLR method (the one you are marking as a proc) to some other name, and then change the CREATE PROCEDURE statement to use that changed name. That should hopefully do it.

Niels
|||

I think my problem originates from the fact that you cannot complie an assembly using a web refrence using csc. I redesigned my assembly with a web refrence to http://ProdWeb1/PaymentProc/PaymentProc.asmx called ProdBilling which I can test operation ChargeCard successfully.

using System;

using System.Collections.Generic;

using System.Text;

namespace PayProcAssembly

{

public class PaymentProcessing

{

[Microsoft.SqlServer.Server.SqlProcedure]

public static string ChargeCard(int Account, float Amount)

{

ProdBilling.PayProcessing serv = new ProdBilling.PayProcessing();

string result = serv.ChargeCard(Account, Amount);

SqlContext.Pipe.Send(result);

}

}

}

When I run

csc /target:library PaymentProcessing.cs

I get

Error: The type or namespace name 'ProdBilling could not be found (are you missing a using directive or an assembly reference?)

I was told I needed to create a proxy using WSDL.exe but it seems when I ran

wsdl /o PaymentProc.cs /n PaymentProc http://ProdWeb1/PaymentProc/PaymentProc.asmx

It messed up my code. I cant even find the web refrence anymore. Is this correct that I have to use wsdl or is there an easier way?

Accessing a web service using clr in SQL 2005

I need to access a billing webservice from SQL. I createde a new c# class project and made a web refrence to the web service "ProdBilling".

Here is the code of my assembly

using System.Data;
using Microsoft.SqlServer.Server;
using System.Data.SqlTypes;
namespace PaymentProc
{
public class PaymentProc
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void ChargeCard(int account, int amount)
{
string Response;
ProdBilling.Service serv = new ProdBilling.Service();
Response = serv.ChargeCard(account, amount);
SqlContext.Pipe.Send(Response);
}
}
}

I then ran WSDL

wsdl /oStick out tongueaymentProc.cs /nStick out tongueaymentProc http://ProdWeb1/PaymentProc/PaymentProc.asmx

Then compliled

csc /target:library PaymentProc.cs

and added the assembly
CREATE ASSEMBLY PaymentProc from 'D:\ProdCode\PaymentProc.dll' WITH
PERMISSION_SET = UNSAFE

I cannot figure out how to refrence the chargecard method

I have tried

CREATE PROCEDURE PaymentProc
@.Account int,
@.Amount int
AS
EXTERNAL NAME PaymentProc.[PaymentProc.PaymentProc].ChargeCard

It seems wsdl.exe put all this serialization code

namespace PaymentProc {
using System.Diagnostics;
using System.Web.Services;
using System.ComponentModel;
using System.Web.Services.Protocols;
using System;
using System.Xml.Serialization;

///
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="ServiceSoap", Namespace="http://ProdWeb1/PaymentProc")]
public partial class PaymentProc : System.Web.Services.Protocols.SoapHttpClientProtocol {

private System.Threading.SendOrPostCallback ChargeCardOperationCompleted;

///
public PaymentProc()
{
this.Url = "http://ProdWeb1/PaymentProc/PaymentProc.asmx";
}

///
public event ChargeCardCompletedEventHandler ChargeCardCompleted;

///
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://ProdWeb1/PaymentProc/ChargeCard", RequestNamespace="http://ProdWeb1/PaymentProc", ResponseNamespace="http://ProdWeb1/PaymentProc", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string ChargeCard(int account, int amount) {
object[] results = this.Invoke("ChargeCard", new object[] {
account,
amount});
return ((string)(results[0]));
}
.................

When I run

CREATE PROCEDURE PaymentProc
@.Account int,
@.Amount int
AS
EXTERNAL NAME PaymentProc.[PaymentProc.PaymentProc].ChargeCard

I get error

Method, property or field 'ChargeCard' of class 'PaymentProc.PaymentProc' in assembly 'PaymentProc' is not static.

Any ideas? This seemsed so straitforward in the beginning.

Change your ChargeCard CLR method (the one you are marking as a proc) to some other name, and then change the CREATE PROCEDURE statement to use that changed name. That should hopefully do it.

Niels
|||

I think my problem originates from the fact that you cannot complie an assembly using a web refrence using csc. I redesigned my assembly with a web refrence to http://ProdWeb1/PaymentProc/PaymentProc.asmx called ProdBilling which I can test operation ChargeCard successfully.

using System;

using System.Collections.Generic;

using System.Text;

namespace PayProcAssembly

{

public class PaymentProcessing

{

[Microsoft.SqlServer.Server.SqlProcedure]

public static string ChargeCard(int Account, float Amount)

{

ProdBilling.PayProcessing serv = new ProdBilling.PayProcessing();

string result = serv.ChargeCard(Account, Amount);

SqlContext.Pipe.Send(result);

}

}

}

When I run

csc /target:library PaymentProcessing.cs

I get

Error: The type or namespace name 'ProdBilling could not be found (are you missing a using directive or an assembly reference?)

I was told I needed to create a proxy using WSDL.exe but it seems when I ran

wsdl /o PaymentProc.cs /n PaymentProc http://ProdWeb1/PaymentProc/PaymentProc.asmx

It messed up my code. I cant even find the web refrence anymore. Is this correct that I have to use wsdl or is there an easier way?

Saturday, February 25, 2012

Access rights...

Hello,
I want to restrict the database not to be accessed from anywhere except my webservice...I mean, my client applications or anyone else can not be able to access the database...
How can I do this?
Thanks very much...

Are you looking for something similar to what was discussed in the following thread?

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=52094&SiteID=1

If not, can you explain what exactly you are trying to protect?

Thanks
Laurentiu

Friday, February 24, 2012

Access Remote SQL SERVER

Hi :)

Is there a way that i can use to connect to SQL SERVER of my WebService Provider ??

I mean how do i upload my database to the SQL SERVER of my WebService Provider ?

ThanksIf the ISP has allowed you to (by opening port 1433) you can.

Otherwise, you should check with the ISP to see how they suggest uploading databases.|||Thanks for the reply :)

They have given me the port number witch its not 1433 ..its another one ...but what software could i use ...i mean a manager ...i have some trials instaled ...but on the connection option theres no place for the port number ...

is there a correct way to do the connection ?

Thanks|||You can use Enterprise Manager. If you have the SQL Server client installed, there is a Client Network Utility that will allow you to set a port for the connection. Without the SQL Server client installed, I am not sure how the other tools you may have work. I would pick up the SQL Server developer's edition, which I think sells for US$40.00 or so.