相关疑难解决方法(0)

将多个参数POST到WCF服务

我正在努力了解WCF,所以我的问题可能很愚蠢.我相信我对"GET"操作有着坚定的理解.我现在正在进行一些"POST"操作.我的问题是,我可以使用WebInvoke编写一个接受多个参数的WCF服务操作吗?或者,当我发布数据时,它是否只接受一个序列化参数?

谢谢!

c# wcf

9
推荐指数
2
解决办法
2万
查看次数

如何使用webinvoke方法(Post或PUT)在wcf rest中传递多个body参数

我在WCF中编写了一个REST服务,我在其中创建了一个方法(PUT)来更新用户.对于这种方法,我需要传递多个身体参数

[WebInvoke(Method = "PUT", UriTemplate = "users/user",BodyStyle=WebMessageBodyStyle.WrappedRequest)]
[OperationContract]
public bool UpdateUserAccount(User user,int friendUserID)
{
    //do something
    return restult;
}
Run Code Online (Sandbox Code Playgroud)

虽然如果只有一个参数,我可以传递用户类的XML实体.如下:

var myRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);
myRequest.Method = "PUT";
myRequest.ContentType = "application/xml";
byte[] data = Encoding.UTF8.GetBytes(postData);
myRequest.ContentLength = data.Length;
//add the data to be posted in the request stream
var requestStream = myRequest.GetRequestStream();
requestStream.Write(data, 0, data.Length);
requestStream.Close();
Run Code Online (Sandbox Code Playgroud)

但是如何传递另一个参数(friendUserID)值?谁能帮我?

wcf webinvoke parameter-passing

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

wcf ×2

c# ×1

parameter-passing ×1

webinvoke ×1