简体   繁体   中英

.NET 3.5 ASMX Web Service - Invoked via .NET 3.5 Service Reference - Common Class Reuse

I have a .NET 3.5 web service with a single web method that looks something like this:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Collections.Generic;
using System.Web.Services;

namespace Webservice1
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class WebService1 : WebService
    {
        [WebMethod]
        public List<Model.Person> HelloWorld()
        {
            var person1 = new Model.Person { FirstName = "Champa", LastName = "Chameli", TimeSpan = new TimeSpan(12,10,9,8)};
            var person2 = new Model.Person { FirstName = "Shamu", LastName = "Ramu", TimeSpan = new TimeSpan(12,10,9,8) };
            var persons = new List<Model.Person> { person1, person2 };
            return persons;
        }
    }
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System.Runtime.Serialization;
namespace Model
{
    [DataContract]
    public class Person
    {
        [DataMember]
        public string FirstName{ get; set; }
        [DataMember]
        public string LastName { get; set; }
        [DataMember]
        public System.TimeSpan TimeSpan { get; set; }
    }
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The Person class is defined in a common .NET 3.5 assembly that is also available (as a project reference) to a .NET 3.5 application that calls the webservice via a Service Reference (not a .NET compatibility web reference).

The issue is that the service reference namespace contains its own, auto generated, implementation of Person. So the auto generated Service Reference method, available on the proxy SOAP client, has the following signature:

public WebApplication1.WebServiceReference1.Person[] HelloWorld()

I also tried using the svcutil command with the dataContractOnly option but I get the error

"C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0A\\Bin\\svcutil" http:///CrossfirePortalServices/Leasing/WebService1.asmx /o:"C:\\temp\\WebApplication1\\WebApplication1\\WebService1.cs" /s /tcv:Version35 /r:"c:\\temp\\WebApplication1\\Model\\bin\\Debug\\Model.dll" /language:C# /n:*,RPCommonClasses.Services.WebService1 /dataContractOnly

Error: The input read from 'http:///CrossfirePortalServices/Leasing/WebService1.asmx' is inconsistent with other options. If you would like more help, type "svcutil /?"

I am keen to find a solution where I can use Model domain throughout the entire framework rather than having to translate the different types in the Model domain to the different types in the ServiceReference domain for requests and vice versa for responses.

Also we cannot change asmx webservices to WCF since our IT department is against it. Any suggestions on how I can accomplish this task?

There is good news and bad news. Good news is that it is possible and officialy supported. The bad news is that it is rather complicated.

Please refer to this MSDN article for example of sharing class library between web references. The same applies to your scenario.

http://msdn.microsoft.com/en-us/library/Aa480505.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM