c# - Handling WCF Faults for non-WCF clients -


I have created a WCF service that will be accessed by both WCF clients and non WCF clients. I have created my own class for FaultException handling below;

  [DataContract] Public class error response {[DataMember] Public String ErrMsg {get; set;}}  

I

  [ServiceContract] public interface IService {[Operation Contract] [FaultContract (typeof (ErrorResponse) for my service interface) [WebInvoke (Method = "POST", UriTemplate = "/ XML / GetTypes", BodyStyle = WebMessageBodyStyle.Bare)] TypeResponse XMLTypes (TypeRequest TypeRequest); }  

I have XmlTypes in my method;

  Public Stable Type Resource XmlTypes (TypeRequest TypeRequest) {// // Doing something / raises error ErrorResponse OErrorResponse = New errorRespons (); OErrorResponse.ErrMsg = "Something Happened"; FaultCode oFaultCode = New FaultCode ("12345"); New fault expansion & lt; ErrorResponse & gt; (Oiarararspons, New Foltresn ( "fault throw the cause"), new FaultCode ( "Taiprcvensfail" New FaultCode ( "TypeNotFound"));  

This is fine for a WCF client

However, when calling a non-WCF client, for example WebClient UploadString (I know that I can use the service reference, this is for testing purposes ), I

WebClient oClient = New WebClient (); OClient.Encoding = UTF8Encoding.UTF8; OCli ent.Headers.Add ( "Content-type", "application / xml"); try {txtResponse.Clear (); SRequest = "& lt; TypeRequest & gt; & lt; UserId & gt; 1 & lt; / user ID & lt; password & gt; asdax12 & lt; / password & gt; & lt; / TypeRequest & gt; "; TxtResponse.Text = oClient.UploadString (" http: // Sthaniyhost: 49562 / Service. svc / XML / XmlTypes "," POST ", sRequest) Kostring ();} catch (exception ex) {txtResponse.Text = ex.ToString ();}

I have this in my web configured file The following is taken from the example:

   & Lt; HttpTransport / & gt; & Lt; / Binding & gt; & Lt; / CustomBinding & gt; & Lt; / Binding & gt; & Lt; Services & gt; & Lt; Service name = "MySpace 12 service" & gt; & Lt; endpoint address = "binding =" custombinding "binding configuration =" BasicHttpSoapl2 binding "binding namespace =" Maispe 12 service namespace "contract =" Maispe 12 service "& gt; & Lt; / endpoint & gt; & Lt; / Service & gt ; & Lt; / Services & gt; & lt; /system.serviceModel>  

Where am I going?

Do you have any other web method that you can call successfully (from the same non-WCF client)

Since you have a 400 HTTP error, I guess That call is not being created correctly or not, so if you can successfully call in any other way the same service that will help us to ensure that the call is correct

< / Html>

Comments