Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
331 views
in Technique[技术] by (71.8m points)

c# - 服务参考覆盖类型(Service Reference overwrites type)

I created 3 projects: class library (referenced by two following), web service and client application.

(我创建了3个项目:类库(以下两个引用),Web服务和客户端应用程序。)

Web service is added as Service reference (Connected Service) to the client project.

(Web服务已作为服务引用(连接的服务)添加到客户端项目。)

The problem is that I need to get from web service an object of type ClassLibrary.AB but by a default I got ClientProject.ServiceProject.AB (as the service reference seems to work as any other reference it expects AB type to be a member of reference type, in this scenario ServiceProject.AB ).

(问题是我需要从Web服务中获取ClassLibrary.AB类型的对象,但是默认情况下,我得到了ClientProject.ServiceProject.AB (因为该服务引用似乎可以像其他任何引用一样工作,因此它期望AB类型是该成员的成员)引用类型,在这种情况下为ServiceProject.AB )。)

I tried to switch "Configure Service Reference... > Reuse types in referenced assemblies" on and off but without success.

(我试图打开和关闭“配置服务引用...>重用引用程序集中的类型”,但是没有成功。)

Could you please give me some directions how should I configure it to get object of ClassLibrary namespace?

(您能否给我一些指导,我应该如何配置它以获取ClassLibrary命名空间的对象?)

Code for clarification:

(澄清代码:)

Class library AB class:

(类库AB类:)

using System;
using System.Runtime.Serialization;

namespace ClassLibrary
{
    [Serializable]
    [DataContract(Name = "AB", Namespace = "ClassLibrary")]
    public class AB
    {
        [DataMember(Name = "a")]
        private int a;
        [DataMember(Name = "b")]
        private byte[] b;
        <some_more_methods_here>
    }
}

Web service method:

(Web服务方法:)

using ClassLibrary;
[...]
[WebMethod]
public AB calledMethod(byte[] x)
{
    int a = [...]
    byte[] b = [...]
    AB ab = new AB(a, b);    
    return ab;
}

Failing client code:

(客户端代码失败:)

using ClassLibrary;
[...]
byte[] x = [...]
var serviceProjectSoapClient = new ServiceProject.ServiceProjectSoapClient();
AB ab = new AB();
ab = serviceProjectSoapClient.calledMethod(x); // here error occurs because of types missmatch
  ask by TajniakOsz translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...