WCF 代理类中缺少方法参数

发布于 2024-10-19 13:30:10 字数 1019 浏览 2 评论 0原文

我有一个 WCF 方法定义如下:

[OperationContract]
Message GetSourceData(SourceDataQuery sourceDataQuery);

实际实现是这样的:

public Message GetSourceData(SourceDataQuery sourceDataQuery)
    {

        IEnumerable<ExportRow> sourceData = repo.GetData();

        var customBodyWriter = new CustomBodyWriter(sourceData);
        var message = Message.CreateMessage(MessageVersion.Soap11, "GetSourceData", customBodyWriter);

        return message;
    }

SourceDataQuery 对象:

[MessageContract]
public class SourceDataQuery
{
    [MessageBodyMember]
    public int DataSourceId { get; set; }

    [MessageBodyMember]
    public int[] FiledIds { get; set; }

    [MessageBodyMember]
    public string Filter { get; set; }

    [MessageBodyMember]
    public string Sort { get; set; }
}

我的问题是当我将此 WCF 服务添加到另一个项目并通过添加服务引用创建代理时,我的代理类有一个 GetSourceData 方法,但是它的输入参数丢失。它不需要任何参数。我可以看到 SourceDataQuery 对象是在代理类中正确生成的。

知道为什么缺少输入参数吗?

I have a WCF method defined as below:

[OperationContract]
Message GetSourceData(SourceDataQuery sourceDataQuery);

And actual implementation is something like this:

public Message GetSourceData(SourceDataQuery sourceDataQuery)
    {

        IEnumerable<ExportRow> sourceData = repo.GetData();

        var customBodyWriter = new CustomBodyWriter(sourceData);
        var message = Message.CreateMessage(MessageVersion.Soap11, "GetSourceData", customBodyWriter);

        return message;
    }

SourceDataQuery object:

[MessageContract]
public class SourceDataQuery
{
    [MessageBodyMember]
    public int DataSourceId { get; set; }

    [MessageBodyMember]
    public int[] FiledIds { get; set; }

    [MessageBodyMember]
    public string Filter { get; set; }

    [MessageBodyMember]
    public string Sort { get; set; }
}

My problem is when I add this WCF service to another project and create a proxy by adding a service reference, my proxy class have a GetSourceData method but its input paramater is missing. It doesnt take any parameter.. I can see that SourceDataQuery object is generated within proxy class correctly though.

Any idea why input parameter is missing?

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

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

发布评论

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

评论(2

短暂陪伴 2024-10-26 13:30:10

尝试使用 DataContract 代替。它可能会解决你的问题

[DataContract]
      public class SourceDataQuery
        {

            [DataMember]
            public int DataSourceId { get; set; }

            ....
        }

Try using DataContract instead. It might solve your problem

[DataContract]
      public class SourceDataQuery
        {

            [DataMember]
            public int DataSourceId { get; set; }

            ....
        }
晨曦慕雪 2024-10-26 13:30:10

尝试将serviceclient对象包装在IService接口中,例如写:

ServiceReference1.IService1 serviceclient = new ServiceReference1.Service1Client();

而不是

ServiceReference1.Service1Client serviceclient = new ServiceReference1.Service1Client();

Try to wrap the serviceclient object in the IService interface, for example write:

ServiceReference1.IService1 serviceclient = new ServiceReference1.Service1Client();

instead of

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