开发者

WCF service that returns xml element

In my wcf service I need to return the status code as xmlelement. If the POST method is 开发者_如何学JAVAsucess then I should pass

<xmlelement>success</xmlelement>

to the client. if theres any error then I should pass

<xmlelement>error</xmlelement> 

to the client. Any idea how to do this. And is there any good site i can get good material abou this. Thanks for your help.


Back in the day, ASMX web services only allowed you to return simple types. This often meant returning a string that contained XML. But, WCF did away with that. You can still return XML as a string, if you want. But, there's no need to. You can return any .NET object you want from your WCF service.

For something as simple as "it worked vs. it failed with this error" I often just return a string. If the string is empty, that indicates success. Otherwise, the string contains the error message.

You could also use a simple class or struct to do something like this:

public struct Result
{
    bool Success,
    string ErrorMessage
}

Hope that helps...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜