Reputation: 599
I am getting the error below while trying to add WCF service to WCFTestClient. I went through a number of solutions on the web but I couldn't get it to work.
Can someone help me with the issues? I am also providing my config file for service:
Content Type application/soap+xml; charset=utf-8 was not supported by service 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
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file
must be added to the host's app.config file. System.Configuration does not
support config files for libraries. -->
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttp" allowCookies="true"
maxReceivedMessageSize="20000000"
maxBufferSize="20000000"
maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32"
maxArrayLength="200000000"
maxStringContentLength="200000000"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="WCFTradeLibrary.TradeService">
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="basicHttp"
contract="WCFTradeLibrary.ITradeService">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint
above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faul`enter code here`ts for
debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception info`enter code here`rmation -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Upvotes: 59
Views: 212082
Reputation: 231
As suggested by others this happens due to service client mismatch.
I ran into the same problem, when was debugging got to know that there is a mismatch in the binding. Instead of WSHTTPBinding I was referring to BasicHttpBinding. In my case I am referring both BasicHttp and WsHttp. I was dynamically assigning the binding based on the reference. So check your service constructor as shown below
Upvotes: 3
Reputation: 5384
I also came across the same problem. In my case, I was using transfermode = streaming with Mtom. As it turns out, I had named one of my variables (for a structure), "HEADER". This conflicted with the message element [http://tempuri.org/:HEADER] as part of the http service download. Clearly, one must avoid using "reserved" words as parameter name.
Upvotes: 0
Reputation: 1
I had the same problem and solved it by using EnumMemberAttribute for enum member's attribute. If you are using enum type as data contract and its members attributed with DataMemberAttribute, same error occurs. You must use EnumMemberAttribute for members of enum
Upvotes: 0
Reputation: 1
I was getting same error while using WebServiceTemplate spring ws [err] org.springframework.ws.client.WebServiceTransportException: Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'. [415] [err] at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:665). The WSDL which i was using has soap1.2 protocol and by default the protocol is soap1.1 . When i changed the protocol using below code, it was working
MessageFactory msgFactory = MessageFactory.newInstance(javax.xml.soap.SOAPConstants.SOAP_1_2_PROTOCOL);
SaajSoapMessageFactory saajSoapMessageFactory = new SaajSoapMessageFactory(msgFactory);
saajSoapMessageFactory.setSoapVersion(SoapVersion.SOAP_12);
getWebServiceTemplate().setMessageFactory(saajSoapMessageFactory);
Upvotes: 0
Reputation: 246
My problem was our own collection class, which was flagged with [DataContract]. From my point of view, this was a clean approach and it worked fine with XmlSerializer but for the WCF endpoint it was breaking and we had to remove it. XmlSerializer still works without.
Not working
[DataContract]
public class AttributeCollection : List<KeyValuePairSerializable<string, string>>
Working
public class AttributeCollection : List<KeyValuePairSerializable<string, string>>
Upvotes: 0
Reputation: 2497
I run into naming problem. Service name has to be exactly name of your implementation. If mismatched, it uses by default basicHttpBinding
resulting in text/xml
content type.
Name of your class is on two places - SVC markup and CS file.
Check endpoint contract too - again exact name of your interface, nothing more. I've added assembly name which just can't be there.
<service name="MyNamespace.MyService">
<endpoint address="" binding="wsHttpBinding" contract="MyNamespace.IMyService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
Upvotes: 17
Reputation: 97
I too had the same error in trace logs. My newly created function in API was throwing the same error but to my surprise, the old functions were performing good. The issue was - My contract data members had few variables of type object. soap-xml was not able to handle it well, however, I can see that array of object types (object[]) were getting passed without any issues. Only a simple object type was not getting parsed by soap. This could be one more reason why the services throw the above error.
Upvotes: 0
Reputation: 1232
For me, it was very difficult to identify the problem because of a large number of methods and class involved.
What I did is commented (removed) some methods from the WebService interface and try, and then comment another bunch of methods and try, I kept doing this until I found the method that cause the problem.
In my case, it was using a complex object which cannot be serialized.
Good luck!
Upvotes: 1
Reputation: 751
In my case same error was caused by missing
[DataContract]
...
[DataMember]
attributes in the returned data type.
Check for that and try addinging those and see if it helps.
Upvotes: 0
Reputation: 111
I had to add the ?wsdl parameter to the end of the url. For example: http://localhost:8745/YourServiceName/?wsdl
Upvotes: -3
Reputation: 61
I experienced the same error message. I managed to fix it:
In my case the error was that I missed the [datacontract] and [datamember] attributes in the parent class of my returned class. The error message was misleading.
[OperationContract]
List<MyClass> GetData();
[DataContract]
public class MyClass : MyParentClass
{
[DataMember]
public string SomeString { get; set; }
}
// Missing DataContract
public class MyParentClass
{
// Missing DataMember
public int SomeNumber { get; set; }
}
Upvotes: 0
Reputation: 165
Here is the example of a web.config that solve the issue for me. Pay attention on the <binding name="TransportSecurity" messageEncoding="Text" textEncoding="utf-8">
Upvotes: 9
Reputation: 15113
My case had a different solution. The client was using basichttpsbinding[1] and the service was using wshttpbinding.
I resolved the problem by changing the server binding to basichttpsbinding. Also, i had to set target framework to 4.5 by adding:
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
[1] the comunication was over https.
Upvotes: 1
Reputation: 11
This error may occur when WCF
client tries to send its message using MTOM extension (MIME type application/soap+xml
is used to transfer SOAP XML in MTOM
), but service is just able to understand normal SOAP messages (it doesn't contain MIME parts, only text/xml type in HTTP request).
Be sure you generated your client code against correct WSDL
.
In order to use MTOM on server side, change your configuration file adding messageEncoding attribute:
<binding name="basicHttp" allowCookies="true"
maxReceivedMessageSize="20000000"
maxBufferSize="20000000"
maxBufferPoolSize="20000000"
messageEncoding="Mtom" >
Upvotes: 1
Reputation: 7549
In my case one of the classes didn't have a default constructor - and class without default constructor can't be serialized.
Upvotes: 6
Reputation: 657
check the client config file that identified to the web.config on the binding section
Upvotes: -4
Reputation: 253
I had the same problem, got it working by "binding" de service with the service behaviour by doing this :
Gave a name to the behaviour
<serviceBehaviors> <behavior name="YourBehaviourNameHere">
And making a reference to your behaviour in your service
<services>
<service name="WCFTradeLibrary.TradeService" behaviorConfiguration="YourBehaviourNameHere">
The whole thing would be :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttp" allowCookies="true"
maxReceivedMessageSize="20000000"
maxBufferSize="20000000"
maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32"
maxArrayLength="200000000"
maxStringContentLength="200000000"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="WCFTradeLibrary.TradeService" behaviourConfiguration="YourBehaviourNameHere">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttp" contract="WCFTradeLibrary.ITradeService">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="YourBehaviourNameHere">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faul`enter code here`ts for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception info`enter code here`rmation -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Upvotes: 6