0
votes

I have a very basic webservice using WCF (C#, .NET 4.0), to return an hello message.

The deployment under IIS 7 and running it is ok, but when I do svcutil.exe http://localhost:4569/Service.svc?wsdl through the CMD to test the webservice I get:

the remote server returned an error: 415 cannot proccess the message because the content type 'aplication/soap+xml charset=utf8' was not the expected type 'text/xml charset=utf8'

When trying to add the service reference (to create a client) I get

An existing connection was forcibly closed by the remote host Metadata contains a reference that cannot be resolved: 'http://localhost:4569/Service.svc'. Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:4569/Service.svc. The client and service bindings may 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'..

I'm pretty sure that the problem is under my Web.config file:

    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
      <system.serviceModel>
<services>
         <service name="Service">
             <endpoint name="soap" 
                 address="http://localhost:4569/Service.svc" 
                 binding="basicHttpBinding" 
                 contract="IService" />
             <endpoint name="mex" address="mex" binding="mexHttpBinding" 
                       contract="IMetadataExchange" />
         </service>
         <behaviors>
            <serviceBehaviors>
               <behavior>
                  <serviceMetadata httpGetEnabled="true"/>
                  <serviceDebug includeExceptionDetailInFaults="false"/>
               </behavior>
            </serviceBehaviors>
</services>
         </behaviors>
         <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
    </configuration>

Anyway, here's my code:

IService.cs:

[ServiceContract]
public interface IService
{
    [OperationContract]
    string getMessage();
}

My service.cs has the method

public class Service : IService
{
    public string getMessage()
    {
        return "Ola servico";
    }
}

I really don't know what is happening, did some tests after some research but no success.

Service.svc

<%@ ServiceHost Language="C#" Debug="true" Service="Service" CodeBehind="~/App_Code/Service.cs" %>        
1
You're not showing us the interesting (and important) parts of your config! The <services> section in <system.serviceModel> on the server side and the contents of the *.svc file! Please add those - otherwise we're left guessing at best....marc_s
is that the entire config file? are the services, bindings and endpoints defined in code?MLT
The error message would indicate that you're mixing SOAP and REST. It seems you want to retrieve a WSDL, yet it would appear as if you're using the REST binding (webHttpBinding) ....marc_s
@marc_s I tried, edited question, but not working..Tiago
when you say 'running it is ok' do you mean in the browser and have you tried connecting to it via wcftestclient? also, and this may be a stupid question, but is your getMessage() implementing the service contract?MLT

1 Answers

1
votes

You have no service and endpoint defined in your config. Try adding

<services>
  <service name="Service"> <!-- name should match the name in your .svc file (if you open it with a text editor) -->
    <endpoint name="soap" address="" binding="basicHttpBinding" contract="IService" />
    <endpoint name="mex" address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>