zoukankan      html  css  js  c++  java
  • Web Reference for a WCF Service has Extra “IdSpecified” Parameter ?

    Question:
     
    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?

    Answer: 

    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.

  • 相关阅读:
    linux设备驱动编写_tasklet机制(转)
    Class create, device create, device create file (转)
    android MTK驱动背光唤醒流程
    sysfs接口函数的建立_DEVICE_ATTR(转)
    Android图形显示之硬件抽象层Gralloc(hal 转)
    misc设备
    Android 呼吸灯流程分析
    Linux输入子系统(转)
    Oracle与MySQL的比较[内容来自网络]
    Oracle数据库分区相干知识点
  • 原文地址:https://www.cnblogs.com/mschen/p/4262090.html
Copyright © 2011-2022 走看看