zoukankan      html  css  js  c++  java
  • WCF客户端引用带有 int bool 类型的方法时,会自动加上一个Specified参数的 解决方法 Web Reference for a WCF Service has Extra “IdSpecified” Parameter 摘自网络

    问题:

    I created a WCF service that exposed a method that has one paramater:

    public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }
    }

    The service has two endpoints defined (wsHttpBinding and basicHttpBinding) so that it would be compatable with older clients.

    The service runs just fine in a .NET 3.0 and .NET 3.5 client app. However, when I create a .NET 2.0 client, the GetData method requires 2 parameters: an integer (expected) and a bool parameter called valueSpecified (unexpected). I never defined the second parameter. Why is this happening and how can I get rid of the second parameter?

    回答:

    Another way to avoid the extra boolean parameter to be generated on the client proxy when using .NET 2.0 is to switch to RPC-style enconding in the service contract (the default for both WCF and ASMX is Document Style).
    This way the XmlSerializer on the client will make sure that the parameter always appears in the SOAP requests since it's part of the SOAP 1.1 specification, which is enforced when using the RPC-Style encoding.

    In WCF you can specify the encoding style using the DataContractFormat attribute, either at the service or at the operation level.

    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        [DataContractFormat(Style = OperationFormatStyle.Rpc)]
        string GetData(int value);
    }
     

    More information on the differences between RPC Style and Document Style encoding in SOAP can be found here.

    In any case please consider carefully the implications of changing the contract of your services, since it can potentially break compatibility with any existing clients.

  • 相关阅读:
    算法的时间复杂度
    二叉树递归建立和遍历
    数据挖掘之分类算法---knn算法(有matlab例子)
    C链表之创建简单静态链表
    ID3决策树算法原理及C++实现(其中代码转自别人的博客)
    adobe reader安装完成之前被中断,错误代码150210解决方法
    Oracle性能诊断艺术-读书笔记
    先对结果集排序然后做update、delete操作
    索引聚簇因子相关
    直方图及low_value、high_value
  • 原文地址:https://www.cnblogs.com/haoliansheng/p/2812777.html
Copyright © 2011-2022 走看看