.NET SOAP Common Types

Is there a way to create web services to specify the types to use? In particular, I want to be able to use the same type on the client and server to reduce code duplication.

In a simplified example:

    public class Name
    {
        public string FirstName {get; set;}
        public string Surname { get; set; }

        public override string ToString()
        {
            return string.Concat(FirstName, " ", Surname);
        }
    }

I do not want to recode the parts of the functionality in my class. Another thing is that any code that exists that manipulates this class will not work on the client side, since the client side class that was generated will be a different type.

+1
source share
2 answers

, , SOAP, . , , :

, . . . . . , .

, :

  • - Visual Studio wsdl.exe. Reference.cs( .vb) . , , .
  • - wsdl.exe /sharetypes.
+2

, - , - :

public struct Whatever
{
    public string A;
    public int B;
}

-, :

[WebMethod]
public Whatever GiveMeWhatever()
{
    Whatever what = new Whatever();
    what.A = "A";
    what.B = 42;
    return what;
}

- :

Webreference.Whatever what = new Webreference.Whatever();
what.A = "that works?";
what.B = -1; // FILENOTFOUND

, ( -).

0

All Articles