Hi,
I'm trying to return exceptions from a WCF Service using FaultExceptions. I
got the service compiled and running. But I get an error while adding a
service reference to it. The error reads:
"
Attempting to download metadata from
'http://localhost:4619/WCFService1/Service.svc' using WS-Metadata Exchange or
DISCO.
Error: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension:
System.ServiceModel.Description.DataContractSerial izerMessageContractImporter
Error: ISerializable type with data contract name 'ServiceException' in
namespace 'http://schemas.datacontract.org/2004/07/' cannot be imported. The
data contract namespace cannot be customized for ISerializable types and the
generated namespace 'BScreened.WS.Test.localhost' does not match the required
CLR namespace ''. Check if the required namespace has been mapped to a
different data contract namespace and consider mapping it explicitly using
the namespaces collection.
XPath to Error Source:
//wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='IService']
"
Something seems to be wrong with the Service Exception class but I don't
understand what. Ideas anyone?
My service looks like this:
----------
Service.cs
----------
using System;
using System.ServiceModel;
using System.Runtime.Serialization;
[ServiceContract()]
public interface IService
{
[OperationContract]
[FaultContract(typeof(ServiceException))]
string Echo(string value);
}
[Serializable]
public class ServiceException : ApplicationException, ISerializable
{
public ServiceException() { }
public ServiceException(string message) : base(message) { }
public ServiceException(string message, Exception inner) : base(message,
inner) { }
protected ServiceException(
SerializationInfo info,
StreamingContext context)
: base(info, context) { }
}
public class Service : IService
{
public string Echo(string value)
{
if (value == null)
throw new FaultException<ServiceException>(new ServiceException());
return value;
}
}
-----------
Service.svc
-----------
<% @ServiceHost Language=C# Debug="true" Service="Service"
CodeBehind="~/App_Code/Service.cs" %>
----------
Web.config
----------
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.serviceModel>
<services>
<!-- Before deployment, you should remove the returnFaults behavior
configuration to avoid disclosing information in exception messages -->
<service name="Service" behaviorConfiguration="returnFaults">
<endpoint contract="IService" binding="wsHttpBinding"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="returnFaults" >
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>