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.

时间: 2024-08-30 03:44:53

Web Reference for a WCF Service has Extra “IdSpecified” Parameter ?的相关文章

How to make a simplest WCF service work on Win7 with VS2010

You know as a beginner to learn WCF, the first thing is to make a simplest WCF service work like a classic "Hello World" console application. Now I will introduce the steps by following: 1.Create a "WCF Application Service" like this:

不写画面的网页程序设计,Web API、Web Service、WCF Service

客户有一个系统,经常要连上我方,查询数据 以前的作法是给对方一个账号,让他可以连上我们的DB来查询. 所以,早期的同仁,真的给他们DB链接字符串 客户的Windows程序.网站就真的靠这么危险的方式,连上我们公司的DB. 但怎么想都觉得危险,而且...... 如果对方SQL指令乱下,把效能搞得更烂,岂不是惨兮兮? 如果对方不小心,配置文件被偷走,看到我方DB Connection String怎么办? 几年前的 Internet还没有那么大的带宽,所以还得种种限制,避免他们一次查询太多数据 我接

vs2012.net WebService简单的创建、使用、验证、发布后更改引用地址、web reference、service reference

工作中使用到较多的webservice,学习了一段时间,在这里总结一下在vs中使用webservice的过程和理解. 一 创建(服务器端)   在vs中穿件webservice是比较简单的.下面记录一下步骤. 步骤1:新建一个web项目,注意不能是类库. 步骤2:在新建的web项目上,添加新项--web服务: 自动生成的代码如下: /// <summary> /// WebService1 的摘要说明 /// </summary> [WebService(Namespace = &

WCF Service Configuration Editor的使用

WCF Service Configuration Editor的使用 2014-06-13 通过WCF Service Configuration Editor的配置修改Client端 在上篇文章创建一个简单的WCF程序中, 使用WCF Service Configuration Editor工具生成XML文件来进行WCF的配置,而不是在CS文件中敲代码. 通过WCF Service Configuration Editor的配置 返回 以下是使用WCF Service Configurati

WCF Service Configuration Editor的使用【转】

原文:http://www.cnblogs.com/Ming8006/p/3772221.html 通过WCF Service Configuration Editor的配置修改Client端 参考 在上篇文章创建一个简单的WCF程序中, 通过编码的方式进行终结点的添加和服务行为的定义,但在进行真正的WCF应用开发时,一般会直接是通过配置的方式进行. 对于初学者来说,WCF的配置显得过于复杂,直接对配置文件进行手工编辑不太现实.在这种情况下,可以直接使用VS提供的配置工具WCF Service

如何创建一个AJAX-Enabled WCF Service

  原创地址:http://www.cnblogs.com/jfzhu/p/4041638.html 转载请注明出处   前面的文章中介绍过<Step by Step 创建一个WCF Service >以及<如何使用WCF的Trace与Message Log功能>,本文介绍如何创建一个AJAX-Enabled WCF Service. (一)创建一个WCF AJAX-enabled service 1. 打开Visual Studio 2012,创建一个ASP.NET Empty

用JavaScript调用WCF Service

原文:用JavaScript调用WCF Service 原创地址:http://www.cnblogs.com/jfzhu/p/4039604.html 转载请注明出处 前面介绍过<Step by Step 创建一个WCF Service>和<使用WCF的Trace与Message Log功能>,本文介绍一下如何用JavaScript来调用WCF Service. WCF Service的代码如下: IHelloService.cs using System.ServiceMode

MVC应用程序使用Wcf Service

原文:MVC应用程序使用Wcf Service 前一篇Insus.NET有演示过MVC应用程序使用Web Service, 此篇Insus.NET想继续演示Service,不过是WCF Service. 两者实施起来,多少有些不一样. 在Services目录下,创建一个Calculator.svc 服务.创建成功之后,它会生生成一个接口以及一个svc的文件: 在Calculator.svc中,它是实作上面的接口,而且均实现了四个方法: WCF Service创建好之后,正常的话,它能浏览: 下面

探讨 : Host在IIS上的WCF Service的执行方式

一个WCF请求由两个线程来完成 运行在IIS上的WCF service, 你可能会注意到一个比较有趣的现象. 当WCF service接收到一个请求时, 这个请求实际上会有两个线程在执行这个请求. 一个线程是来自于CLR的ThreadPool的线程. 这是一个Worker Thread用于接收.svc页面的访问请求. 另外一个线程是 I/O 线程, 用于执行WCF的逻辑. 你可以参考下面的实例代码. 该代码用于模拟一个WCF执行时间比较长的场景. [ServiceContract]public