asmx asp.net Web服务返回多个类wsdl [英] asmx asp.net webservice return multiple classes wsdl

查看:119
本文介绍了asmx asp.net Web服务返回多个类wsdl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在为客户开发Web服务.我们不打算抛出SoapExceptions,因此,我们捕获了每个异常服务器端,并返回了一个自定义的Exception类.

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

现在的问题是,由于我的网络方法返回的是[Object]类型.生成的wdsl不包含命令或异常.

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.

我可以将[Object]更改为[Order]或[MyException],但是在wsdl中仅生成其中之一.

I can change the [Object] to [Order] Or [MyException], but only one of them is generated in the wsdl.

那么有人对我应该如何处理这个有一个想法吗?我想在wsdl中同时使用MyException类型和Order类型,但是我无法使其正常工作.

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.

谢谢大家.

推荐答案

如果您定义了MyException

If your definition of MyException

Public Class MyException
        inherits System.Exception
    ...
    End Class

那么您就不需要返回自定义异常,只需将其抛出即可.

then you shouldn't need to return the Custom Exception just throw it.

然后您可以定义

Public Function GetOrder(ByVal id As Integer) As Order

    Try
        ...
        Return New Order()
    Catch ex As Exception
        Throw New MyException(ex.Message)
    End Try

End Function

我记得(已经有一段时间了)尝试从Web方法返回多个对象可能非常麻烦

As I recall (and it's been a while) trying to return multiple objects from a web method can prove to be extremely troublesome

这篇关于asmx asp.net Web服务返回多个类wsdl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆