Yes this is the only method, beside this there are anohter one method which are doing inserting in database using the same connection and that case that connection return privately so not access out side of this services. I want to use it out side of this
services in some other application, for this i change this connection method to public from private then it returning an error messages same as earlier.
I need this connection string so that i can use it other application golbally.
The following exception message is indicating that you're trying to return some object which is not serializable by the service runtime:
"Cannot serialize member System.ComponentModel.Component.Site of type System.ComponentModel.ISite because it is an interface. "
and based on my test, if we simply return the string (by calling ToString on Connection object) in webservice webmethod, it should works correctly (here is the test webmethod I use):
[WebMethod]
public string GetConnectionString()
{
var sqlconn = new SqlConnection(@"data source=.\SQLExpress;initial catalog=Northwind;integrated security=True;");
return sqlconn.ToString();
}
Therefore, I'd suggest you recreating a webservice and define a similar webmethod to test it again. Also, you can verify if there is some other webmethods in your service which has directly return the SqlConnection object(that might cause the exception you
pasted above).
it can return a connection string but showing an error message on client side where i am using the connection string . It showing the error message can not implicty convert webservices to System.Data.SQLClient; so still i am in mid way... any idea how to
fix it??
As I mentioned in previous post, we cannot directly return a SqlConnection object in webservice webmethod, but can return the connectionstring as string value. Therefore, in your client, your code can be something like below:
var proxy = new webServiceProxyClass();
// Note, the webmethod returns a string(not any ADO.NET object) string connStr = proxy.GetConnectionString();
var sqlConn = new SqlConnection(connStr);
gopal_74_15
Member
549 Points
264 Posts
Created Web Services for Database connection and in Application!!!!
Apr 30, 2012 12:21 PM|LINK
Hello Friends,
I am creating a web services that allow to make a connection to database. but when i compile the web services, i get an error message
"Cannot serialize member System.ComponentModel.Component.Site of type System.ComponentModel.ISite because it is an interface. "
I have created another web services that allow to insert a record in a database and it is working.... bwlow is the code..
[WebMethod]
public string CreateConnection()
{
SqlConnection connSQL = new SqlConnection("Data Source=INBM-EC92516398\\SQLEXPRESS;Initial Catalog=EngjobSite;Persist Security Info=True;User ID=sa; pwd=Pass@123");
return connSQL.ToString();
}
Ph: 91-8130165954 /9936971939
Email: gopal_74@hotmail.com, gopal_s@live.com
nijhawan.sau...
All-Star
16400 Points
3173 Posts
Re: Created Web Services for Database connection and in Application!!!!
Apr 30, 2012 12:29 PM|LINK
Is this the only method in your service?
And you have pasted the entire code for it? Make sure your web service is not getting non serializable parameters or returning any such values.
gopal_74_15
Member
549 Points
264 Posts
Re: Created Web Services for Database connection and in Application!!!!
Apr 30, 2012 12:49 PM|LINK
Yes this is the only method, beside this there are anohter one method which are doing inserting in database using the same connection and that case that connection return privately so not access out side of this services. I want to use it out side of this services in some other application, for this i change this connection method to public from private then it returning an error messages same as earlier.
I need this connection string so that i can use it other application golbally.
Ph: 91-8130165954 /9936971939
Email: gopal_74@hotmail.com, gopal_s@live.com
Steven Cheng...
Contributor
4197 Points
547 Posts
Microsoft
Moderator
Re: Created Web Services for Database connection and in Application!!!!
May 01, 2012 04:02 AM|LINK
Hi gopal_74_15,
The following exception message is indicating that you're trying to return some object which is not serializable by the service runtime:
"Cannot serialize member System.ComponentModel.Component.Site of type System.ComponentModel.ISite because it is an interface. "
and based on my test, if we simply return the string (by calling ToString on Connection object) in webservice webmethod, it should works correctly (here is the test webmethod I use):
[WebMethod] public string GetConnectionString() { var sqlconn = new SqlConnection(@"data source=.\SQLExpress;initial catalog=Northwind;integrated security=True;"); return sqlconn.ToString(); }Therefore, I'd suggest you recreating a webservice and define a similar webmethod to test it again. Also, you can verify if there is some other webmethods in your service which has directly return the SqlConnection object(that might cause the exception you pasted above).
Feedback to us
Microsoft One Code Framework
gopal_74_15
Member
549 Points
264 Posts
Re: Created Web Services for Database connection and in Application!!!!
May 01, 2012 10:31 AM|LINK
Hello Steve,
it can return a connection string but showing an error message on client side where i am using the connection string . It showing the error message can not implicty convert webservices to System.Data.SQLClient; so still i am in mid way... any idea how to fix it??
Ph: 91-8130165954 /9936971939
Email: gopal_74@hotmail.com, gopal_s@live.com
Steven Cheng...
Contributor
4197 Points
547 Posts
Microsoft
Moderator
Re: Created Web Services for Database connection and in Application!!!!
May 04, 2012 08:09 AM|LINK
Hi gopal,
So what does your current client code look like?
As I mentioned in previous post, we cannot directly return a SqlConnection object in webservice webmethod, but can return the connectionstring as string value. Therefore, in your client, your code can be something like below:
is this what your client code currently doing?
Feedback to us
Microsoft One Code Framework
gopal_74_15
Member
549 Points
264 Posts
Re: Created Web Services for Database connection and in Application!!!!
May 07, 2012 12:04 PM|LINK
Hello Stanely,
Below is the code fro connection in Web Services....
public string GetConnectionString()
{
string contStr = "@Connection String";
var sqlconn = new SqlConnection("conStr");
sqlconn.Open();
return sqlconn.ToString();
}
I have save and adding this in Client Application with name of ConnectionApp.
Now tell me is there any possiblilty access this string...???? or any possiblity to access it by function argument.
I am waiting your mail....
Ph: 91-8130165954 /9936971939
Email: gopal_74@hotmail.com, gopal_s@live.com