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

佐手、 提交于 2019-12-11 13:40:30

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/12222606/net-3-5-asmx-web-service-invoked-via-net-3-5-service-reference-common-clas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!