我正在尝试编写一个模拟服务来模仿我无法访问的第三方Web服务,直到生产。
假设我有方法'Foo',它接受参数'WidgetName'。请求正文可能如下所示:
<Foo xmlns="http://tempuri.org/">
<WidgetName>Gadget</WidgetName>
...
</Foo>
我想要的是这样的:
<Foo xmlns="http://tempuri.org/" WidgetName="Gadget">
...
</Foo>
请注意,'WidgetName'是'Foo'的属性。我可以用[XmlAttribute]
装饰参数,如下所示:
[WebMethod]
...
public string Foo([XmlAttribute]string WidgetName) {
//...
}
但是当它说完所有结果时......
XmlSerializer attribute System.Xml.Serialization.XmlAttributeAttribute is not valid in sourceSystemType. Only XmlElement, XmlArray, XmlArrayItem, XmlAnyAttribute and XmlAnyElement attributes are supported when IsWrapped is true.
好.Bare
不是我想要的(与.Wrapped
相反),对吗?因为这导致<Foo ..></Foo>
完全消失。如果我设置为'Bare',则在尝试更新Web服务引用时会出现此错误(使用完整的实际代码):
There was an error downloading 'http://localhost:48319/FooWS/FooWS.asmx/_vti_bin/ListData.svc/$metadata'. The request failed with the error message...
说Request format is unrecognized for URL unexpectedly ending in '/_vti_bin/ListData.svc/$metadata'.
我从[XmlAttribute]
移除Foo(string WidgetName)
时,错误更新消失了我只是不知道从哪里开始。