通用类重用 - .NET 3.5 ASMX Web服务 - 通过.NET 3.5服务引用调用 [英] .NET 3.5 ASMX Web Service - Invoked via .NET 3.5 Service Reference - Common Class Reuse

查看:159
本文介绍了通用类重用 - .NET 3.5 ASMX Web服务 - 通过.NET 3.5服务引用调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web方法,它看起来是这样的一个.NET 3.5 Web服务:

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

而Person类是在一个共同的.NET 3.5组件,它也可以定义(作为项目基准)为.NET 3.5应用程序调用通过服务引用(而不是.NET兼容Web引用)的Web服务。

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).

的问题是服务引用命名空间包含它自己的,自动生成的,执行的人。所以自动生成的服务引用的方法,可代理的SOAP客户端,具有以下签名:

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()

我也尝试使用SvcUtil工具命令与dataContractOnly选择,但我得到的错误

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

C:\ Program Files文件\微软的SDK \的Windows \ v6.0A \ BIN \ SvcUtil工具   HTTP:///CrossfirePortalServices/Leasing/WebService1.asmx   /o:"C:\temp\WebApplication1\WebApplication1\WebService1.cs/秒   / TCV:Version35 /r:"c:\temp\WebApplication1\Model\bin\Debug\Model.dll   /语言:C#/n:*,RPCommonClasses.Services.WebService1   / dataContractOnly

"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

错误:读取输入   HTTP:///CrossfirePortalServices/Leasing/WebService1.asmx   是与其他选项不一致。如果您想了解更多的帮助,请键入   SvcUtil工具/?

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.

此外,我们不能改变ASMX Web服务WCF的,因为我们的IT部门却表示反对。我如何能完成这个任务有什么建议?

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

推荐答案

有一个好消息和一个坏消息。好消息是,这是可能的,officialy支持。坏消息是,它是相当复杂的。

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.

请参照例如Web引用之间共享类库的这个MSDN文章。这同样适用于您的方案。

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

这篇关于通用类重用 - .NET 3.5 ASMX Web服务 - 通过.NET 3.5服务引用调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆