Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

wcf - Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'

6,471 views
Skip to first unread message

TS

unread,
Jun 16, 2010, 4:15:28 PM6/16/10
to
I am having the hardest time trying to get my simple wcf service working. I
have done everything I'm supposed to do. I have googled for hours and follow
all recommendations and still get the error.

When I navigate to the service, hosted in IIS 7, I get this:
This is a Windows© Communication Foundation service.

Metadata publishing for this service is currently disabled.

If you have access to the service, you can enable metadata publishing by
completing the following steps to modify your web or application
configuration file:
........................................

when I try to run the project, WCF test Client opens up and I get this error
and I want to say the reason is the content type error part:

Error: Cannot obtain Metadata from http://localhost/WcfService1/Service1.svc
If this is a Windows (R) Communication Foundation service to which you have
access, please check that you have enabled metadata publishing at the
specified address. For help enabling metadata publishing, please refer to
the MSDN documentation at
http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error
URI: http://localhost/WcfService1/Service1.svc
Metadata contains a reference that cannot be resolved:
'http://localhost/WcfService1/Service1.svc'.
Content Type application/soap+xml; charset=utf-8 was not supported by
service http://localhost/WcfService1/Service1.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'..HTTP GET
Error URI: http://localhost/WcfService1/Service1.svc The HTML document
does not contain Web service discovery information.
---------------------------------------
I have tried both wsHttpBinding and basicHttpBinding with no luck.

Any help would be greatly appreciated.

thanks
TS

<?xml version="1.0"?>
<configuration>

<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="Service1" behaviorConfiguration="returnFaults">
<!--
<host>
<baseAddresses>
<add baseAddress="http://localhost/WcfService1/Service1.svc"/>
</baseAddresses>
</host> -->
<endpoint contract="IService1" binding="wsHttpBinding"
address="http://localhost/WcfService1/Service1.svc" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding"
address="http://localhost/WcfService1/mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="returnFaults">
<!-- To avoid disclosing metadata information, set the value below
to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" /> <!--
policyVersion="Policy15" -->
<!-- To receive exception details in faults for debugging
purposes, set the value below to true. Set to false before deployment to
avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

</configuration>

namespace WcfService1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change
the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{

[OperationContract]
string GetData(int value);

[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);

// TODO: Add your service operations here
}


// Use a data contract as illustrated in the sample below to add composite
types to service operations.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";

[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}

[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfService1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change
the class name "Service1" in code, svc and config file together.
[Serializable]
public class Service1 : IService1
{
public string GetData(int value)
{
//WebOperationContext.Current.OutgoingResponse.ContentType =
"application/soap+xml";
return string.Format("You entered: {0}", value);
}

public CompositeType GetDataUsingDataContract(CompositeType composite)
{
//WebOperationContext.Current.OutgoingResponse.ContentType =
"application/soap+xml";

if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
}


TS

unread,
Jun 16, 2010, 5:25:24 PM6/16/10
to
OK, I got it to work by commenting out the stuff below. Please tell me what
is wrong with the commented out section...why doesn't it like the services
tag info?

<?xml version="1.0"?>
<configuration>

<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>

<!-- <services>


<service name="Service1" behaviorConfiguration="returnFaults">

<host>
<baseAddresses>
<add baseAddress="http://localhost/WcfService1/Service1.svc"/>
</baseAddresses>
</host>

<endpoint contract="WcfService1.IService1"
binding="basicHttpBinding"

address="http://localhost/WcfService1/Service1.svc" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding"
address="http://localhost/WcfService1/mex" />
</service>

</services> -->
<behaviors>
<serviceBehaviors>
<behavior> <!-- name="returnFaults"> -->
<serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />


<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

</configuration>

TS

"TS" <manofs...@nospam.nospam> wrote in message
news:OMvWrCZD...@TK2MSFTNGP05.phx.gbl...

TS

unread,
Jun 16, 2010, 5:30:13 PM6/16/10
to
OK, I have now narrowed it down to one thing. The below xml works correctly.
The only thing missing is that I removed the name of the behavior and
removed this: behaviorConfiguration="returnFaults":

Tell me why I cannot use the name like this?

thanks !!!!!

<?xml version="1.0"?>
<configuration>

<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="Service1">

<host>
<baseAddresses>
<add baseAddress="http://localhost/WcfService1/Service1.svc"/>
</baseAddresses>
</host>

<endpoint contract="WcfService1.IService1"
binding="basicHttpBinding"

address="http://localhost/WcfService1/Service1.svc" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding"
address="http://localhost/WcfService1/mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>

<serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />

<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

</configuration>

"TS" <manofs...@nospam.nospam> wrote in message
news:OMvWrCZD...@TK2MSFTNGP05.phx.gbl...

Steven Cheng

unread,
Jun 17, 2010, 4:11:31 AM6/17/10
to
Hi TS,

So you mean that the service can work correctly if you comment the entire
<services> .... </services> configuration section?

In .NET 4.0, WCF has provided a default endpoint/binding feature which
makes the service configuration more convenient. Developers can simply host
service without explicitly specify endpont/binding info and the WCF runtime
will choose a default endpoint and binding based on the protocol (in
address).

For your case, you use http protocol, the default binding should also be
basicHttpBinding and enable Metadata. I'm wondering whether you can use the
baseAddress of your service( xxx.svc) to get the wsdl document in
webbrowser when using the original configuration setting or will it also
report error?

In addition, you can turn on WCF tracing at service side and client-side to
see whether it can capture more detailed error information at underlying
channel level.

#Configuring Tracing
http://msdn.microsoft.com/en-us/library/ms733025.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

--------------------
From: "TS" <manofs...@nospam.nospam>
References: <OMvWrCZD...@TK2MSFTNGP05.phx.gbl>
Subject: Re: wcf - Cannot process the message because the content type

'application/soap+xml; charset=utf-8' was not the expected type 'text/xml;
charset=utf-8'

Date: Wed, 16 Jun 2010 16:25:24 -0500

TS

unread,
Jun 18, 2010, 2:27:01 PM6/18/10
to
as long as I remove behaviorConfiguration from service tag and name from
behavior tag it seems to all work, why?

I thought the problem was then fixed but apparently it is ignoring the
services tags I have set up because it always uses basicHttpBinding which is
the default even though I specify wsHttpBinding. in the trace log I see that
it says 'configuration evaluation context not found" & "no matching
<service> tag was found. Default endpoints added".

Then later it throws two errors with the same old exception in it:
"Content Type application/soap+xml; charset=utf-8 was sent to a service
expecting text/xml; charset=utf-8. The client and service bindings may be
mismatched."

NOte that I am able to invoke the methods of the service and it seems to
work and return correct values (and can step thru code) using the WCF Test
Client.

Please advise

thanks
TS

""Steven Cheng"" <stc...@online.microsoft.com> wrote in message
news:smkz3SfD...@TK2MSFTNGHUB02.phx.gbl...

Steven Cheng

unread,
Jun 22, 2010, 9:25:38 AM6/22/10
to
Thanks for reply TS,

That sounds unexpected as removing "behaviorConfiguration" and behavior
setting will not affect "binding" of your service. What is your current
app.config/web.config looking like? Is the <services>/<service> tag still
putting in it?

Also, is the service working correctly when hosting in a console
application or a VS hosted web project out of IIS? I suggest you check
whether the IIS 7 application pool is set to .NET framework version 4.0.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


--------------------
From: "TS" <manofs...@nospam.nospam>


Subject: Re: wcf - Cannot process the message because the content type
'application/soap+xml; charset=utf-8' was not the expected type 'text/xml;
charset=utf-8'

Date: Fri, 18 Jun 2010 13:27:01 -0500

0 new messages