Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. webservice return

webservice return

Scheduled Pinned Locked Moved C#
question
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B brsecu

    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.

    P Offline
    P Offline
    Pete OHanlon
    wrote on last edited by
    #3

    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.

    B 1 Reply Last reply
    0
    • C Christian Graus

      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 )

      B Offline
      B Offline
      brsecu
      wrote on last edited by
      #4

      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'

      C 1 Reply Last reply
      0
      • P Pete OHanlon

        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.

        B Offline
        B Offline
        brsecu
        wrote on last edited by
        #5

        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

        C 1 Reply Last reply
        0
        • B brsecu

          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'

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #6

          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 )

          1 Reply Last reply
          0
          • B brsecu

            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

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #7

            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 )

            B 1 Reply Last reply
            0
            • C Christian Graus

              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 )

              B Offline
              B Offline
              brsecu
              wrote on last edited by
              #8

              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"); } }

              N 1 Reply Last reply
              0
              • B brsecu

                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"); } }

                N Offline
                N Offline
                Nick Parker
                wrote on last edited by
                #9

                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

                B 1 Reply Last reply
                0
                • N Nick Parker

                  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

                  B Offline
                  B Offline
                  brsecu
                  wrote on last edited by
                  #10

                  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); } }

                  N 1 Reply Last reply
                  0
                  • B brsecu

                    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); } }

                    N Offline
                    N Offline
                    Nick Parker
                    wrote on last edited by
                    #11

                    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

                    B 1 Reply Last reply
                    0
                    • N Nick Parker

                      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

                      B Offline
                      B Offline
                      brsecu
                      wrote on last edited by
                      #12

                      Thanks 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); } } }

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups