asmx asp.net webservice返回多个类wsdl
我们正在为客户开发网络服务。我们不应该抛出 SoapExceptions,因此,我们捕获服务器端的每个异常,并返回一个自定义的 Exception 类。
Public Class Order
...
End Class
Public Class MyException
...
End Class
然后在我的 web 服务中一个函数(webmethod):
Public Function GetOrder(ByVal id As Integer) As Object
Try
...
Return New Order()
Catch ex As Exception
Return New MyException(ex.Message)
End Try
End Function
现在的问题是,因为我的 webmethod 返回类型 [Object]。生成的 wdsl 不包含订单或异常。
我可以将 [Object] 更改为 [Order] 或 [MyException],但 wsdl 中只生成其中之一。
那么有人知道我应该如何处理这个问题吗?我想要在我的 wsdl 中同时使用 MyException 类型和 Order 类型,但我就是无法让它工作。
谢谢大家。
We are developing a webservice for a client. We are not supose to throw SoapExceptions, so instead, we catch every exception server side, and return a custom Exception class.
Public Class Order
...
End Class
Public Class MyException
...
End Class
And then in my webservice a function (webmethod):
Public Function GetOrder(ByVal id As Integer) As Object
Try
...
Return New Order()
Catch ex As Exception
Return New MyException(ex.Message)
End Try
End Function
The problem now is, that since my webmethod is returning the type [Object]. The wdsl that is generated does not contain the order, or the exception.
I can change the [Object] to [Order] Or [MyException], but only one of them is generated in the wsdl.
So does anybody have an idea of how i should handle this? I want both the MyException type and the Order type in my wsdl, but i just cant get it working.
Thank you all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您定义了 MyException
那么您不需要返回自定义异常,只需抛出它即可。
那么你可以定义
我记得(已经有一段时间了)尝试从 Web 方法返回多个对象可能会非常麻烦
If your definition of MyException
then you shouldn't need to return the Custom Exception just throw it.
then you can define
As I recall (and it's been a while) trying to return multiple objects from a web method can prove to be extremely troublesome
如果您确实想返回多个对象,那么也许您应该创建一个“包装器”对象,例如如下所示:
然后更改您的方法以返回该类的实例,并将属性 Order 或 Exception 设置为相应的值:
If you really want to return multiple objects, then maybe you should create a "wrapper" object, e.g something like this:
Then change your method to return an instance of that class, with either the property Order or Exception set to the respective value: