WCF SOAP Web Service Handling Bad Enums - C# .Net - c#

I have a WCF SOAP Web Service built using svcutil to generate the contract classes. The WSDL has enums and thus the default is to deserialize the XML to an enum class. This works great when the user sends in the correct enum.
<priceType>List</priceType>
<priceType>Net</priceType>
However, if the user enters a bogus value:
<priceType>I love dogs</priceType>
The deserializer throws and exception and they get a SOAP Fault that there was a server error. How could I respond with a better error message that their enum value is invalid?

Related

Soap Message to C# Object

I have a WSDL file and using same a proxy service reference and classes for various object gets generated.
The WCF service implemented using the interface from generated file (reference.cs) works well when service is triggered with some soap message using SOAP UI.
Now I have various soap messages and needs to test the service function using unit testting or some console app. For that I need to convert these soap messages to actual .NET object so I can invoke the service function or some part of that function using the object (which normally received to service operation when invoked)
Tried different approaches like TypeConverter, SoapFormatter etc to desearlize the soap message but non helps since the soap message contains lots of namespaces and nested object hierachy.
How one can do it OR can any one give idea , what methods internally convert the soap message to actual object which are parameters of function ??
How I've done in past is actually imported WSDL in SOAPUI, with all its services, and got clean Services with formated SOAP methods, and afterwards its a piece of cake to create models in C#, java or whatever language.
SoapUI
Create empty project,
Add WSDL to empty project (provide path),
Get correct structure of SOAPs (request)đ
create models

WCF in "service reference" client gives less information in exception message than "web reference" client

I should call a web service in my C# application.
When I add a service reference in Visual Studio to consume the service, in an exception situation I get this message:
An HTTP Content-Type header is required for SOAP messaging and none
was found.
But, when I add a web reference the message is more rich and easy to understand the problem. The final part of this message is a business error message generated by the service. I was provided an invalid authentication token parameter for that service so this error message is returned:
Client found response content type of '', but expected 'text/xml'.
The request failed with the error message:
--
WEB SERVICE ERROR : UNAUTHENTICATED_ACCESS
I was preferred to use "service reference" approach but now I am in doubt.
Is there a way to improve this kind of exceptions or to log raw response using "service reference"?
I think the first message is much clearer.
It's telling you exactly what the problem is, which is the HTTP Content-Type header is missing from the service response. While this header is not mandatory, the HTTP specs say you should use it (from here):
Any HTTP/1.1 message containing an entity-body SHOULD include a
Content-Type header field defining the media type of that body.
Microsoft obviously built into their proxy generation tooling the assumption that this header will always be present.
And no, you should not use WebReference. It's from .net 1.1

Custom Tool Warning error verifying some XML Schemas during export

I have a web service that I want to consume driven by PHP and SOAP. I can add the web service just fine and I get the list of methods when I added(used add service reference when added). But now I get an error:
Warning 1 Custom tool warning: There was an error verifying some XML Schemas generated during export:
Type 'http://www.w3.org/2001/XMLSchema:struct' is not declared. localPATH:Reference.svcmap 1 1 SOAP_Webservice_Test
From what I understand, this is due to a specific type that I have in my PHP Soap API. I have googled but none of the mentioned fixes does it for me.
Any suggestions how to proceed with my debugging?
Closing this because the problem was not in the client, it was in the soap server I tried to refer to.

Should I use response codes, exceptions or textual messages for my service responses?

I am building a WCF based service application in .Net. I am currently designing the contracts.
Should I use response codes, exceptions or textual messages for my service responses to report service result status?
They will be consumed by web applications and other systems.
You should take a look at FaultContracts. See http://msdn.microsoft.com/en-us/library/system.servicemodel.faultcontractattribute.aspx
Your Fault Contract can include a (string based) error code for client side processing, and / or a textual message for display to users.
If your service, or rather you as a service designer, don't know what a (future) client application will want to do with an error message (display or process), include both.
In my opinion best is to use response enum (code) that make sense to client. Apart from it returning message may increase the dataload on the WCF service.
E.g.
throw new FaultException<InvalidArgumentException>(new InvalidArgumentException(),Constants.MaxLengthFields.PhoneNumber)), Response.OrderIdMissing);
[DataContract, Serializable]
enum Response
{
[EnumMember]
OrderIdMissing,
[EnumMember]
ProductCodeInvalid,
}
There are several articles available on the web. Please go though them for more concrete information.
http://blogs.msdn.com/b/brajens/archive/2007/04/23/exception-handling-in-wcf-web-service.aspx
http://blogit.create.pt/blogs/marcosilva/archive/2008/05/18/Developing-a-WCF-Service-%5F2D00%5F-Fault-Exceptions-AND-FAULT-Contracts.aspx
http://blogs.msdn.com/b/brajens/archive/2007/04/23/exception-handling-in-wcf-web-service.aspx

Consuming iWay business services (iBSP) from a .net client

I'm trying to generate a proxy to access some iWay business services (iBSP) from VS2010.
When I use "Add Service Reference", I get and exception trying to consume any service:
XmlSerializer attribute System.Xml.Serialization.XmlAttributeAttribute is not valid in cid. Only XmlElement, XmlArray, XmlArrayItem, XmlAnyAttribute and XmlAnyElement attributes are supported when IsWrapped is true.
This exception happens before the request is actually made (I can't see any request in fiddler).
When I use "Add Web Service", the request goes OK and I can see the soap response with many records in fiddler, but in .net the result array comes empty (null to be more precise).
Any ideas?

Categories