By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,473 Members | 3,504 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,473 IT Pros & Developers. It's quick & easy.

Error when adding Service References containing Exception classes.

P: n/a
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
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 '' 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:

Something seems to be wrong with the Service Exception class but I don't
understand what. Ideas anyone?
My service looks like this:

using System;
using System.ServiceModel;
using System.Runtime.Serialization;

public interface IService
string Echo(string value);

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;

<% @ServiceHost Language=C# Debug="true" Service="Service"
CodeBehind="~/App_Code/Service.cs" %>

<?xml version="1.0"?>
<configuration xmlns="">
<!-- 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"/>
<behavior name="returnFaults" >
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true"/>
<compilation debug="true"/>

Apr 30 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.