webservice return
-
This should be pretty easy but I'm having so many problems with it. I'm following someone elses code and cant figure out how he did this. One of the webmethods returns 3 parameters and it uses a class of somesort to do it. We had to reverse engineer to get the code so its not complete. [WebMethod] Public Class1 HelloWorld(int i1, string str1, string str2) { try } //Code } Catch } return Class1(1,2,3) } { return Class1(0,0,0) } } How is this possible? Thanks in advance.
It looks as though it's one of two options. Either the Class1 mentioned in the catch/finally block refers to a method on the web service which returns an instance of Class1, or you are missing a new statement on the return Class1 constructor.
Please visit http://www.readytogiveup.com/ and do something special today. Deja View - the feeling that you've seen this post before.
-
why would it not be possible ? Importing a web service will import the types it exposes, including enums and classes.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
It looks as though it's one of two options. Either the Class1 mentioned in the catch/finally block refers to a method on the web service which returns an instance of Class1, or you are missing a new statement on the return Class1 constructor.
Please visit http://www.readytogiveup.com/ and do something special today. Deja View - the feeling that you've seen this post before.
-
I'm sorry I guess I wasnt clear. I get this error when i try to build. 'Service.Test222(string, string, string)' is a 'method' but is used like a 'type'
Oh, OK. The code looks wrong to me, shouldn't say return *new* Class1(x,y,z); ?
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
I guess my real question is how to make class1 work as a type. When i put class1 in front of Hello world I get an error. How do i declare/create it so I can use that class1 type
It should exist as webserviceNamespace.class1. Can you see it declared in the code created when you import the webservice ?
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
It should exist as webserviceNamespace.class1. Can you see it declared in the code created when you import the webservice ?
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
You are getting me closer. Again I appreciate it. Here is my exact code(I've simplified it). If i want to return those three arguments what do i have to do? using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Class1 : System.Web.Services.WebService { } public class Service : System.Web.Services.WebService { public Service () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public Class1 Hello() { return new Class1("1","2","3"); } }
-
You are getting me closer. Again I appreciate it. Here is my exact code(I've simplified it). If i want to return those three arguments what do i have to do? using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Class1 : System.Web.Services.WebService { } public class Service : System.Web.Services.WebService { public Service () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public Class1 Hello() { return new Class1("1","2","3"); } }
You are close, now you need to provide an overloaded constructor for Class1 to take your 3 string arguements. It would look something like this:
public class Class1 : WebService
{
public Class1(string one, string two, string three)
{
this.one = one;
this.two = two;
this.three = three;
}
public Class1 Hello()
{
return new Class("1", "2", "3");
}
}- Nick Parker Microsoft MVP - Visual C#
My Blog | My Articles -
You are close, now you need to provide an overloaded constructor for Class1 to take your 3 string arguements. It would look something like this:
public class Class1 : WebService
{
public Class1(string one, string two, string three)
{
this.one = one;
this.two = two;
this.three = three;
}
public Class1 Hello()
{
return new Class("1", "2", "3");
}
}- Nick Parker Microsoft MVP - Visual C#
My Blog | My Articleswhen i run that (see the code below) I get this error. Class1 cannot be serialized because it does not have a parameterless constructor. public class Class1 : System.Web.Services.WebService { public Class1(string strOne, string strTwo) { strOne = strOne; strTwo = strTwo; } [WebMethod] public Class1 HelloWorld(string str1, string str2) { return new Class1(str1,str2); } }
-
when i run that (see the code below) I get this error. Class1 cannot be serialized because it does not have a parameterless constructor. public class Class1 : System.Web.Services.WebService { public Class1(string strOne, string strTwo) { strOne = strOne; strTwo = strTwo; } [WebMethod] public Class1 HelloWorld(string str1, string str2) { return new Class1(str1,str2); } }
brsecu wrote:
when i run that (see the code below) I get this error. Class1 cannot be serialized because it does not have a parameterless constructor.
Just add a default constructor as well that has no parameters:
public class Class1 : WebService
{
// default constructor
public Class1(){}// overloaded constructor public Class1(string s1, string s2, string s3) { // ...your code here }
}
- Nick Parker Microsoft MVP - Visual C#
My Blog | My Articles -
brsecu wrote:
when i run that (see the code below) I get this error. Class1 cannot be serialized because it does not have a parameterless constructor.
Just add a default constructor as well that has no parameters:
public class Class1 : WebService
{
// default constructor
public Class1(){}// overloaded constructor public Class1(string s1, string s2, string s3) { // ...your code here }
}
- Nick Parker Microsoft MVP - Visual C#
My Blog | My ArticlesThanks for your patience with me. OK i did that and it builds but now I get this error: Cannot serialize member System.ComponentModel.MarshalByValueComponent.Site of type System.ComponentModel.ISite because it is an interface. using System; using System.Data; using System.Web; using System.Collections; using System.Web.Services; using System.Web.Services.Protocols; using System.ComponentModel; namespace WebService1 { /// /// Summary description for Service1 /// [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] public class Class1 : System.Web.Services.WebService { public string _strOne; public string _strTwo; public Class1() { } public Class1(string strOne, string strTwo) { this._strOne = strOne; this._strTwo = strTwo; } [WebMethod] public Class1 HelloWorld(string str1, string str2) { str1 = "1"; str2 = "2"; return new Class1(str1,str2); } } }