Reporting an error from a POST Web Service - web-services

I'm developing a web service (in asp.net) and I would like to have each web method report to whoever called it when an internal error occurs - for example when input validation has failed.
When I expose my web service with SOAP such errors can be reported by raising a SoapException. But what if I expose my web service with plain POST (aka Http-Post)? Other than returning a 500 Error HTTP status code, is there a standard for reporting errors or raising exceptions in this case?

Change the response object to contain a status filed, and error message (or only error message, and check at the receiver if empty), and set it properly instead of throwing an exception.

I've always just returned the 500 status code, along with a textual description of the error. Just make sure it's documented so the client can handle it correctly.

Related

How to disable Verbose Error Messages of soap web services?

How to disable Verbose Error Messages of soap web services?
I have one web method with some para.
Example Req:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<GenerateTestRequest xmlns="http://tempuri.org/">
<sId>1#!aB</sId>
<mobileNum>12345678</mobileNum>
<srcType>1</srcType>
</GenerateTestRequest>
</Body>
</Envelope>
When an unexpected input was supplied into sId para instead of Int32, Then the web service returned an exception within the response content.
Example Res:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:DeserializationFailed</faultcode>
<faultstring xml:lang="en-SG">The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:sId. The InnerException message was 'There was an error deserializing the object of type System.Int32. The value '1#!aB' cannot be parsed as the type 'Int32'.'. Please see InnerException for more details.</faultstring>
</s:Fault>
</s:Body>
</s:Envelope>
I don't want to display response content of exception message. Is there any way to turn off stack trace or exception details?
Is there any way to turn off stack trace or exception details?
Yes, by doing proper error handling for the SOAP web service.
A SOAP request can receive back a successful SOAP response or can receive back an unsuccessful response in the form of a SOAP Fault. People unfortunately focus on the successful cases only and let the framework they are using handle other problems.
Because SOAP is a protocol any exception on the server needs to be converted to a proper Fault response. This needs to be done by the developer by catching any exception and building appropriate Fault responses out of them, with only the needed data inside. For security reasons of course that data can't contain stacktraces or others sensitive information. But like I said, people often neglect to handle the error cases, and the framework can't build custom Faults, it can only build a SOAP fault with details from the exception that occurred, exposing it to the client.
You didn't tag this WCF but the schema namespace on the error code says windowscommunicationfoundation so I'll assume that's the web service framework. You can replace all exception messages with a generic error message by setting IncludeExceptionDetailInFaults to false (I think for your service it is set to true right now). See here for details: either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server
Or, you can do proper error handling and define and document the possible Faults a client can receive and convert any exception to one of those Faults. You can start reading here: Specifying and Handling Faults in Contracts and Services
If you are using any other web service framework or library, the idea is the same, the documentation to read will be different.

IIB10 - BIP3732E: The specified WSDL binding could not be found in the supplied WSDL file

I've created a simple message set in Integration Toolkit 10.0.0.7.
Also created a message flow by drag-and-dropping a WSDL file.
But when deploying, getting this:
BIP2087E: Integration node was unable to process the internal configuration message.
The entire internal configuration message failed to be processed successfully.
Use the messages following this message to determine the reasons for the failure. If the problem cannot be resolved after reviewing these messages, contact your IBM Support center. Enabling service trace may help determine the cause of the failure.
BIP4041E: Integration server 'default' received an administration request that encountered an exception.
While attempting to process an administration request, an exception was encountered. No updates have been made to the configuration of the integration server.
Review related error messages to determine why the administration request failed.
BIP3726E: Failed to setup SOAP transport for node SOAP Input.
The SOAP nodes rely on the configuration of the SOAP transport layer within the integration node, and this has not been initialised correctly. The node will not be operational until the problems have been corrected.
Determine the cause of the error and correct it. Subsequent error messages may contain more information.
BIP3732E: The specified WSDL binding MSETSOAP_HTTP_Binding could not be found in the supplied WSDL file MSET/msetdefns/MSETDEFINITIONService.wsdl.
The WSDL binding MSETSOAP_HTTP_Binding from the target namespace MSETDEFNS associated with message set was not found in the WSDL file MSET/msetdefns/MSETDEFINITIONService.wsdl. This could be because the WSDL file is missing, invalid or corrupt.
Determine the cause of the error and correct it. Ensure that the WSDL file is valid and that it validates correctly.
I've checked: WSDL is ok. SoapUI opens it as well.
What could be the root of problem?
Thanks in advance!
Here is what IBM expert says:
https://developer.ibm.com/answers/questions/352486/bip3732e-the-specified-wsdl-binding-could-not-be-f.html#answer-352715
Also, my workaround:
When dragging WSDL onto message flow and choosing HTTP node instead SOAP - everything runs successfully!
Good luck!

PeopleSoft - Cannot process SOAP fault messages after consuming web service

PT 8.50.15
We have a new integration with a third party system. They have provided the wsdl and I have used the consume web service wizard to consume it into PeopleSoft. All this does is give you the stub messages with a schema attached to each. I have written some peoplecode to send a test message out to the webservice. When the webservice returns a valid result, I have no problems. However, when the webservice returns a fault message, I get the following error:
Integration Gateway - HttpTargetConnector:ExternalApplicationException. Http status code HttpStatusCode returned : 500. (158,10623)
HttpTargetConnector:ExternalApplicationException. External System responded with an Error status. For Http Status Code explanation please check Http protocol Specifications.
I know the webservice is returning the fault message b/c I have tried the same thing in SOAPUI. Does anyone know why PeopleSoft throws up this error ONLY on the fault message?
In addition to the prior response, the 500 error you are seeing should be followed by any soap fault coming back with the response in the errorLog.html file on your gateway (or msgLog depending on the ig.log.level setting in your integrationgateway.properties file. Check the 'response' section, as well as the stack trace for additional information.
On the routing that you are using, click the 'User Exception' check box. Then you will not get the HTTP 500 error. Evaluate the response from the response message. If it's not zero, you will then be able to parse the SOAP fault and see what the returned faultstring is.
Get your Service operation corrected. I Had same issue, After i changed the SO in this code it started working
&msgRequest = CreateMessage(Operation.Operation_name, %IntBroker_Request);

Web Service Error

I have a xml web service and I published it on IIS(localhost). Web service is veriy simple. There is only one method. And there is no exception potential in the web service. I have to use HttpWebRequest instead of adding web reference. I got the following error:
"The remote server returned an error: (500) Internal Server Error". I have checked request xml many times. When I add web referance there is no problem. What's reason of error?
Thanks in advance
Its not possible to tell what the problem is from the information you have provided.
If the web service is one that you have written then you need to get IIS to report a detailed error message on the nature of the problem (by default a restricted error message is shown to prevent would-be attackers obtaining potentially sensitive information), or find another way to obtain detailed error information. Exact instructions on how to do this will depend on the service itself (is this an ASP.Net web service? What version of IIS is this?) however this article - How to Use HTTP Detailed Errors in IIS 7.0 may be of assistance.
If the web service is one that a 3rd party has produced then I'm afraid you need to work with that 3rd party to fix this.
Update: Also try reading Detailed 500 error message, ASP + IIS 7.5 on how to get more detailed error messages.

SOAP <faultstring>

I am having an issue with the SOAP , when I call my services I get this error:
<faultstring>Fault occurred while processing.</faultstring>
The following response is returned which doesn't give a clue where and why the error happens. How can I customize and show a proper detailed message to user so he/she know what they did wrong
I have gone through the CXF customization with outFaultInterceptors and inFaultInterceptors but I am not clear how I am gonna customize cxf.
This means that the web service framework is returning an unchecked exception. Try running the web service on a debugger to see where the exception is happening or wrapping the web service body inside an try/catch to print the stack trace.