Client/Service binding mismatch after adding [FaultContract] to Interface

430 Views Asked by At

i created a WCF webservice in .net/c#. I also created a test client app. everything works fine. Now i wanted to add a custom exception

[DataContract]
[Serializable]
public class MyException : Exception
{    
    public MyException(string message)
        : base()
    {

    }
}

it gets thrown here:

if{ dosomth(); }
else{ 
   MyException mE = new MyException("my error occured");
   throw new FaultException<myException>(mE); 
}

everything alright up until here.

Now i want to add the FaultContract to the Interface:

[OperationContract]
[FaultContract(typeof(MyException))]
Double myMethod(String x, Double y, String z);

And now when i try to update the service reference at my client app after adding the [FaultContract] to the interface i get this error:

There was an error downloading 'http://localhost:51104/MyService.svc/_vti_bin/ListData.svc/$metadata'.
The request failed with HTTP status 400:Bad Request.
Metadata contains a reference that cannot be resolved:
'http://localhost:51104/MyService.svc'.
Content Type application/soap+xml; charset=utf-8 was not supported by service 'http://localhost:51104/MyService.svc'. The client and service bindings my be mismatched.
The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'...

Why does adding the [FaultContract] create a mismatch and what do i need to configure to solve this problem? Is there something wrong with the FaultContract or is it merely a problem with the configuration? (The second would make me wonder why it works without the FaultContract)

I am using .NET 4.5.

here my web.config:

    <?xml version="1.0"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
      <!--
        For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.

        The following attributes can be set on the <httpRuntime> tag.
          <system.Web>
            <httpRuntime targetFramework="4.5" />
          </system.Web>
      -->
      <system.web>
        <compilation debug="true" targetFramework="4.5"/>
        <httpRuntime/>
        <pages controlRenderingCompatibilityVersion="4.0"/>
      </system.web>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="">
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true"/>
      </system.serviceModel>
    </configuration>

and my applications App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IMyService" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:51104/MyService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
                contract="MyService.IMyService" name="BasicHttpBinding_IMyService" />
        </client>
    </system.serviceModel>
</configuration>
0

There are 0 best solutions below