Re: SOAP Endpoint: How to Receive RAISERROR as Exception?



Hi Charles,

thanks a lot for your help!

From your explanation I understood that SQL Server/Visual Studio currently don't support declaring/throwing exceptions caused by RAISERROR through web services. This makes it very awkward to use WEBMETHOD calls because one has to create a wrapper for each WEBMETHOD represented by the created proxy in order to create a type-safe version plus eventually throwing an SqlExeption.

I've now created an issue at Connect now at: https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=341135

Best regards,
www.axeldahmen.com
Axel Dahmen


-----------------
""Charles Wang [MSFT]"" <changliw@xxxxxxxxxxxxxxxxxxxx> schrieb im Newsbeitrag news:HO00lroqIHA.1784@xxxxxxxxxxxxxxxxxxxxxxxxx
Hi Axel,
I understand that you created a SOAP endpoint in your SQL Server 2005
instance and you would like to know how to have your caller to retrieve
your exception message thrown by RAISERROR in your SQL stored procedure.
If I have misunderstood, please let me know.

I reproduced your issue at my side with the following steps:
1. Create a stored procedure in master database
CREATE PROCEDURE hello_world
(@msg nvarchar(256))
as begin
select @msg as 'message'
RAISERROR(N'SELF-SPEAKING',16,1)
end

2. Create an endpoint for soap
CREATE endpoint hello_world_endpoint
STATE=STARTED
AS HTTP (
AUTHENTICATION=(INTEGRATED),
PATH='/sql/demo',
PORTS = (CLEAR)
)
FOR SOAP(
WEBMETHOD 'http://tempuri.org/'.'hello_world'
(NAME='master.dbo.hello_world',FORMAT=ROWSETS_ONLY ),
BATCHES=ENABLED,
WSDL=DEFAULT
)

3. Grant permissions
GRANT CONNECT ON ENDPOINT::hello_world_endpoint TO [mydomain\charles]

4. In my C# client application, add the web reference
"http://localhost/sql/demo?wsdl"; and then invoke it like the following:
=================================
MySQLSOAPProxy.hello_world_endpoint hw = new
CSTest.MySQLSOAPProxy.hello_world_endpoint();
try
{
hw.UseDefaultCredentials = true;
DataSet ds = hw.hello_world("Hello");
MessageBox.Show(ds.Tables[0].Rows[0][0].ToString());
}
catch (Exception ex)
{
MessageBox.Show("Exception: " + ex.Message);
}
=================================

I could not catch the exception thrown by RAISERROR, however this is
expected, RAISERROR does not really throw exceptions instead it just
generates an error message which is returned as a server error message to
the calling application. When you use SOAP protocol, the error message will
be returned in the SOAP message and your client application will not regard
it as an exception. However according to the description of CREATE
ENDPOINT, when you specify FORMAT as ROSETS_ONLY, the SOAP message only
returns the result sets, so the error message will not be returned to the
client. To get the error message, you need to specify the FORMAT as
ALL_RESULTS (default option). In this case, an object array will be
returned in .NET application and you can get the error message according to
the following manners:
==========================================
hw.UseDefaultCredentials = true;
object[] objs = hw.hello_world("Hello");
foreach(object obj in objs)
{
if (obj.GetType() == typeof(MySQLSOAPProxy.SqlMessage))
MessageBox.Show("Sql Error Message: " +
((MySQLSOAPProxy.SqlMessage)obj).Message);
}
==========================================

For more information, please refer to:
CREATE ENDPOINT (Transact-SQL)
http://msdn.microsoft.com/en-us/library/ms181591.aspx

Hope this helps. If you have any other questions or concerns, please feel
free to let me know.


Best regards,
Charles Wang
Microsoft Online Community Support
===========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: msdnmg@xxxxxxxxxxxxxx
===========================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
============================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================


.



Relevant Pages

  • RE: SOAP Endpoint: How to Receive RAISERROR as Exception?
    ... I understand that you created a SOAP endpoint in your SQL Server 2005 ... generates an error message which is returned as a server error message to ... Microsoft Online Community Support ...
    (microsoft.public.sqlserver.connect)
  • Re: Shoot the @#%$ Server - Part 2
    ... http://SomeServer/vdir/sp/MyProcs.wsdl) I get the second error message. ... I'm assuming nwind2 is the vdir and soap is the path for the ... > The first error message indicates that there is simply no matching SQLXML ...
    (microsoft.public.sqlserver.xml)
  • Re: CREATE ENDPOINT (Transact-SQL)
    ... URL Namespaces by Using Http.sys" to try to confirm the endpoint. ... WEBMETHOD 'DayAsNumber' ... It's an HTTP SOAP endpoint - HTTP is the ... the sample application available with SQL Server 2005. ...
    (microsoft.public.sqlserver.tools)
  • SoapLite Error
    ... Element 'XMLRequest' can't be allowed in valid XML message. ... my $soap = SOAP::Lite ... # Format the SOAP envelope ...
    (perl.beginners)
  • Re: 0xc0000011 (USBD_STATUS_XACT_ERROR) ?
    ... The error message is the above. ... The endpoint address does not have anything to do with pipe name, ... If Bulk transfer can loopback, so does Isochronous transfer, am I ...
    (microsoft.public.development.device.drivers)

Loading