出错了!!!!
约定“ISSOPartnerService”的操作“HelloWord”指定要序列化多个请求正文参数,但没有任何包装元素。如果没有包装元素,至多可序列化一个正文参数。请删除多余的正文参数,或将 WebGetAttribute/WebInvokeAttribute 的 BodyStyle 属性设置为 Wrapped。
这绝对是胡扯,明明就定义了WebGet
[OperationContract] [WebGet(BodyStyle = WebMessageBodyStyle.Wrapped)] string HelloWord(string name1, string name2);
问题是,如果在IE里用URL调用,是成功的。有图为证
为毛,为毛??!
原来,VS2010帮我们生成的代码也需要加上WebGet特性才行,不然的话只能将所有参数打包成一个对象作为参数才行。
找到Reference.cs,并找到那个接口函数声明的位置
Code [WebGet(BodyStyle = WebMessageBodyStyle.Wrapped)] [System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/ISSOPartnerService/HelloWord", ReplyAction = "http://tempuri.org/ISSOPartnerService/HelloWordResponse")] string HelloWord(string name1, string name2);
记住需要添加System.ServiceModel.Web.dll引用。
问题是,MS不推荐你手工修改Reference.cs。。不然下次更新引用,这段话又没了,又要自己手工添加一次,烦!
编译运行。。成功了!