使用 WCF 服务时 ASMX 架构会有所不同

发布于 2024-09-04 20:05:39 字数 1935 浏览 1 评论 0原文

我有一个客户端(使用 ASMX“添加 Web 引用”创建)。该服务是WCF。方法的签名因客户端和服务而异。我在该方法中获得了一些不需要的参数。

注意:我对 DataMember 使用 IsRequired = true。

Service:    [OperationContract]
            int GetInt();

Client:     proxy.GetInt(out requiredResult, out resultBool);

您能否帮助我使 WCF 客户端和非 WCF 客户端中的架构不变?我们对此有什么最佳实践吗?

using System.ServiceModel;
using System.Runtime.Serialization;

namespace SimpleLibraryService
{
        [ServiceContract(Namespace = "http://Lijo.Samples")]
        public interface IElementaryService
        {
            [OperationContract]
            int GetInt();

            [OperationContract]
            int SecondTestInt();
        }

        public class NameDecorator : IElementaryService
        {
            [DataMember(IsRequired=true)]
            int resultIntVal = 1;

            int firstVal = 1;

            public int GetInt()
            {
                return firstVal;
            }

            public int SecondTestInt()
            {
                return resultIntVal;
            }
        }

}

Binding =“basicHttpBinding”

using NonWCFClient.WebServiceTEST;

namespace NonWCFClient
{
    class Program
    {
        static void Main(string[] args)
        {
            NonWCFClient.WebServiceTEST.NameDecorator proxy = new NameDecorator();

            int requiredResult =0;
            bool resultBool = false;
            proxy.GetInt(out requiredResult, out resultBool);
            Console.WriteLine("GetInt___"+requiredResult.ToString() +"__" + resultBool.ToString());

            int secondResult =0;
            bool secondBool = false;
            proxy.SecondTestInt(out secondResult, out secondBool);
            Console.WriteLine("SecondTestInt___" + secondResult.ToString() + "__" + secondBool.ToString());

            Console.ReadLine();
        }
    }
}

请帮忙..

谢谢

Lijo

I have a client (created using ASMX "Add Web Reference"). The service is WCF. The signature of the methods varies for the client and the Service. I get some unwanted parameteres to the method.

Note: I have used IsRequired = true for DataMember.

Service:    [OperationContract]
            int GetInt();

Client:     proxy.GetInt(out requiredResult, out resultBool);

Could you please help me to make the schame non-varying in both WCF clinet and non-WCF client? Do we have any best practices for that?

using System.ServiceModel;
using System.Runtime.Serialization;

namespace SimpleLibraryService
{
        [ServiceContract(Namespace = "http://Lijo.Samples")]
        public interface IElementaryService
        {
            [OperationContract]
            int GetInt();

            [OperationContract]
            int SecondTestInt();
        }

        public class NameDecorator : IElementaryService
        {
            [DataMember(IsRequired=true)]
            int resultIntVal = 1;

            int firstVal = 1;

            public int GetInt()
            {
                return firstVal;
            }

            public int SecondTestInt()
            {
                return resultIntVal;
            }
        }

}

Binding = "basicHttpBinding"

using NonWCFClient.WebServiceTEST;

namespace NonWCFClient
{
    class Program
    {
        static void Main(string[] args)
        {
            NonWCFClient.WebServiceTEST.NameDecorator proxy = new NameDecorator();

            int requiredResult =0;
            bool resultBool = false;
            proxy.GetInt(out requiredResult, out resultBool);
            Console.WriteLine("GetInt___"+requiredResult.ToString() +"__" + resultBool.ToString());

            int secondResult =0;
            bool secondBool = false;
            proxy.SecondTestInt(out secondResult, out secondBool);
            Console.WriteLine("SecondTestInt___" + secondResult.ToString() + "__" + secondBool.ToString());

            Console.ReadLine();
        }
    }
}

Please help..

Thanks

Lijo

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦明 2024-09-11 20:05:39

我认为您无法做太多事情来使其“不变” - 这只是从 WCF 服务生成 ASMX 客户端内容的方式。每个客户端堆栈都略有不同,并且可能以稍微不同的方式解释 WSDL 中的服务契约。您对此无能为力......

如果您不希望这样 - 请创建一个 WCF 客户端。

附带说明一下:

public class NameDecorator : IElementaryService
{
   [DataMember(IsRequired=true)]
   int resultIntVal = 1;

这是非常奇怪,您试图将DataMember(一个应该为服务序列化的字段)放入<强>实现服务.....

您应该保留您的服务契约(接口IElementaryService),服务实现(类NameDecorator)和您的数据契约(其他类)分开 - 不要不要混合数据契约和服务实现 - 这肯定会适得其反......

I don't think you can do much to make this "non-varying" - that's just the way the ASMX client side stuff gets generated from the WCF service. Each client-side stack is a bit different from the other, and might interpret the service contract in the WSDL in a slightly different manner. Not much you can do about that.....

If you don't want this - create a WCF client instead.

A remark on the side:

public class NameDecorator : IElementaryService
{
   [DataMember(IsRequired=true)]
   int resultIntVal = 1;

This is very strange how you're trying to put a DataMember (a field that should be serialized across for the service) into the class that implements the service.....

You should keep your service contract (interface IElementaryService), service implementation (class NameDecorator) and your data contracts (other classes) separate - do not mix data contract and service implementation - this is sure to backfire somehow....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文