tags:

views:

25

answers:

3

I need to know how does svcutil and Visual Studio decide which types can be re-used from referenced assemblies when generating a web service proxy class.

I have an assembly with some types that are declared like this:

namespace MYCOMPANY.BO.Accounting
{
    [Serializable, DataContract]
    public class AccountingPackagePutRequest : Request
    {
        // Fields
        [DataMember]
        public IBooking[] bookings;
        [DataMember]
        public IDocument[] documents;

        // Methods
        public AccountingPackagePutRequest();
    }
}

Now I have an ASP.NET 2.0 web service (ASMX) that is declared like this:

[WebService(Namespace = "uri://my_company.com/XXXImport")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class GLSImportAccountingPackagePut : System.Web.Services.WebService
{
    [WebMethod]
    public MYCOMPANY.BO.Accounting.AccountingPackagePutResponse AccountingPackagePut(MYCOMPANY.BO.Accounting.AccountingPackagePutRequest request)
    {
        return new MYCOMPANY.BO.Accounting.AccountingPackagePutResponse();
    }
}

Now I can't force VS nor svcutil to re-use types from the first assembly on the client when generating a proxy class for this web service.

However if I create a similar web service in WCF and try to generate a proxy class for it types from the first assembly are re-used.

What is the problem here and how can I force VS or svcutil to reuse the types for the ASP.NET 2.0 (ASMX) version of the web service?

A: 

Reusing types in a client .DLL that are provided via WCF web service was a new feature with WCF, met with wild applause at the conference I was at when it was announced.

Near as I can tell, sharing types between a client assembly and an ASMX-based web service is not supported by the framework.

kbrimington
This must have been cool :)
Piotr Owsiak
@Piotr: In a real nerdy way, it actually was. ;)
kbrimington
A: 

The difference is contracts and the serializer. Based on the architecture, the client generates proxy to satisfy the contracts of the WCF service. If it can resolve the contract locally, proxy does not get generated. Also, point to note that WCF is nothing but an assembly exposed over a transport protocol.

In case of ASP.net web services, it by default is not contract based. But there is something called as Contract First Web Services that kind of solve this problem.

Perpetualcoder
A: 

As indicated by kbrimington in "classic" ASP.NET web services there is no way to re-use types as it is possible with WCF. I found it stated also here:
1) http://infiniteimprobability.blogspot.com/2009/02/reuse-type-in-web-service.html
2) http://stackoverflow.com/questions/134064/reuse-existing-types-is-ignored-when-adding-a-service-reference
3) http://mark.mymonster.nl/2007/12/16/reusing-class-library-between-web-service-and-consumer/

However with a little bit of will this can be done using Schema Importer Extensions. See:
1) http://mark.mymonster.nl/2007/12/16/reusing-class-library-between-web-service-and-consumer/
2) http://webcache.googleusercontent.com/search?q=cache:Uy_5sKE0OzQJ:www.microsoft.com/belux/msdn/nl/community/columns/jdruyts/wsproxy.mspx+wsproxy+belux&cd=1&hl=en&ct=clnk

The second link is a google cache of the original post that is no longer available. If you have troubles finding it please let me know (I have a local copy of the page).

Piotr Owsiak