webservice返回xml,如下所示。消费客户期待< MyMethodResult>要<回复>。
代码:
[WebMethod]
public MyResponseObj MyMethod(MyRequestObj Request)
{
try
{
MyResponseObj response = new MyResponseObj();
response.Message = "test";
response.Status = Status.success;
return response;
}
catch(Exception ex)
{
throw;
}
}
实际回应:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<MyMethodResponse xmlns="MyNameSpace">
<MyMethodResult>
<Status>success or failure</Status>
<Message>string</Message>
</MyMethodResult>
</MyMethodResponse>
</soap:Body>
</soap:Envelope>
预期回应
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<MyMethodResponse xmlns="MyNameSpace">
**<Response>**
<Status>success or failure</Status>
<Message>string</Message>
**</Response>**
</MyMethodResponse>
</soap:Body>
</soap:Envelope>
答案 0 :(得分:2)
我通过使用[XmlRoot("Response")]
装饰MyResponseObj类来实现它的工作
[XmlRoot("Response")]
public partial class MyResponseObj
{
}