WCF 发布请求中的多个非 url 参数
Multiple non-url parameters in WCF post request
我有一个这样的WCF服务:
public IEnumerable<int> AddProperty(string productId, string propertyClass, Property properties)
我用以下数据调用了它:
{
"Class":{"Name":"aoeu","Restricted":false,"Type":"ScalarProperty"},
"DisplayName":"aoeu",
"Id":"560",
"Value":"aoeu"
}
而且效果很好。现在我想像这样向服务添加另一个Property
:
public IEnumerable<int> AddProperty(string productId, string propertyClass, Property properties, Property properties2)
我应该传递哪些数据?我试过这个:
{
properties: {
"Class":{"Name":"aoeu","Restricted":false,"Type":"ScalarProperty"},
"DisplayName":"aoeu",
"Id":"560",
"Value":"aoeu"
},
properties2: {
"Class":{"Name":"aoeu","Restricted":false,"Type":"ScalarProperty"},
"DisplayName":"aoeu",
"Id":"560",
"Value":"aoeu"
}
}
但它没有用!我尝试了一些不同的方法,但它们都不起作用:(有什么帮助吗?
您可以实现上述操作,如下所示:
[WebInvoke(BodyStyle=WebMessageBodyStyle.Wrapped,UriTemplate = "MultipleProperties?productId={productId}&propertyClass={propertyClass}")]
public IEnumerable<int> AddProperty(string productId, string propertyClass, Property properties, Property properties2)
如果要将多个对象序列化为 POST 请求的一部分,则需要将正文样式设置为 Wraped。
现在假设您的属性类定义如下:
[DataContract]
public class Property
{
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
原始 Http 请求如下所示:
POST http://locahost/XMLService/Service1.svc/AddProperty?productId=1&propertyClass=2 HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json
Content-Length: 134
{"properties": {"boolvalue": "true", "stringvalue": "str"}, "properties2" :{"boolvalue": "true", "stringvalue":"str2"}}
你能这样做吗?
public IEnumerable<int> AddProperty(string productId, string propertyClass, Property[] properties);
然后
[
{
"Class":{"Name":"aoeu","Restricted":false,"Type":"ScalarProperty"},
"DisplayName":"aoeu",
"Id":"560",
"Value":"aoeu"
},
{
"Class":{"Name":"aoeu","Restricted":false,"Type":"ScalarProperty"},
"DisplayName":"aoeu",
"Id":"560",
"Value":"aoeu"
}
]
我假设您只向我们展示了属性代码而不是 productId、属性类等,因为我看不到它们?
相关文章:
- JS:检查URL中的参数,然后迭代一个参数为var的函数
- 传递包含'%的参数'在URL中
- 如何在router.get()方法中传递url作为参数
- javascript中url中的Regex参数
- 如何在reactrouterv2.+中从URL获取参数
- 使用express.具有多个url和可选参数的Router()
- 如何在所有ajax调用中向URL添加参数
- 通过Javascript将HTML中的电话号码与URL参数进行交换
- 如何使用Javascript从URL参数中自动填充文本字段
- XMLHttpRequest.open()AJAX中的参数url
- 如何将Google Analytics配置为将URL参数作为单个页面进行跟踪
- 使用应用程序状态js和视图在angular js url上传递两个参数
- 在url参数javascript中存储键值对列表
- backbone.js-映射标准url参数-使用多个参数
- 模版启动错误-类型错误(“参数”url'必须是字符串,而不是“+类型的url”)
- UI 路由器参数 URL 不起作用,只是重定向到 /
- 在Select2中传递参数url
- 使用jQuery/Javascript(querystring)获取查询字符串参数url值
- Javascript -重定向参数URL只有一次
- 替换url参数-url被破坏