none
Content Type application/soap+xml; charset=utf-8 was not supported by service.The client and service bindings may be mismatched. RRS feed

  • Question

  • I have a very simple WCF service in my ASP.NET web project with one method as below.

    private int counter = 0;
    
    public int Increment()
    {
         counter++;
         return counter;
    }

    The web.config file binding and endpoints are as follows:-

    <?xml version="1.0"?>
    <configuration>
    
        <system.web>
            <compilation debug="true" targetFramework="4.0" />
        </system.web>
    
        <system.serviceModel>
            <bindings>
                <wsHttpBinding>
                    <binding name="WSHttpBinding_IService1" messageEncoding="Text">
                        <reliableSession enabled="true" />
                    </binding>
                </wsHttpBinding>
                <mexHttpBinding>
                    <binding name="MexHttpBinding_IService1" />
                </mexHttpBinding>
                <basicHttpBinding>
                  <binding name="BasicHttpBinding_IService1" />
                </basicHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost:49326/Service1.svc" binding="wsHttpBinding"
                    bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1"
                    name="WSHttpBinding_IService1" />
                <endpoint address="http://localhost:49326/Service1.svc" binding="mexHttpBinding"
                    bindingConfiguration="MexHttpBinding_IService1" contract="ServiceReference1.IService1"
                    name="MexHttpBinding_IService1" />
                <endpoint address="http://localhost:49326/Service1.svc" binding="basicHttpBinding"
                    bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
                    name="BasicHttpBinding_IService1" />
            </client>
            <behaviors>
                <serviceBehaviors>
                    <behavior name="">
                        <serviceMetadata httpGetEnabled="true" />
                        <serviceDebug includeExceptionDetailInFaults="false" />
                    </behavior>
                </serviceBehaviors>
              
            </behaviors>
            <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
        </system.serviceModel>
    </configuration>
    

    When I add the service reference and try to execute the method of WCF service, I get the error : Content Type application/soap+xml; charset=utf-8 was not supported by service.  The client and service bindings may be mismatched. The code which calls the WCF service is as follows:-

    protected void Page_Load(object sender, EventArgs e)
            {
                ServiceReference1.Service1Client obj = new ServiceReference1.Service1Client("WSHttpBinding_IService1");
                //ServiceReference2.Service2Client obj2 = new ServiceReference2.Service2Client();
    
                Response.Write("Session Management - Per Call : " + obj.Increment().ToString() + "<br />");
                Response.Write("Session Management - Per Call : " + obj.Increment().ToString() + "<br />");
                //Response.Write("Session Management - Per Session : " + obj2.Increment().ToString() + "<br />");
                //Response.Write("Session Management - Per Session : " + obj2.Increment().ToString() + "<br />");
            }

    Sunday, March 23, 2014 4:54 PM

Answers

  • Hi,

    The following is my web.config file, it works well:

     <system.diagnostics>
        <sources>
          <source name="System.ServiceModel"
                  switchValue="Information, ActivityTracing"
                  propagateActivity="true" >
            <listeners>
              <add name="xml"/>
            </listeners>
          </source>
          <source name="System.ServiceModel.MessageLogging">
            <listeners>
              <add name="xml"/>
            </listeners>
          </source>
          <source name="myUserTraceSource"
                  switchValue="Information, ActivityTracing">
            <listeners>
              <add name="xml"/>
            </listeners>
          </source>
        </sources>
        <sharedListeners>
          <add name="xml"
               type="System.Diagnostics.XmlWriterTraceListener"
               initializeData="Error.svclog" />
        </sharedListeners>
      </system.diagnostics>
      
        <system.web>
            <compilation debug="true" targetFramework="4.0" />
        </system.web>
    
        <system.serviceModel>
       
        <client>
            <endpoint address="http://localhost:49326/Service1.svc" binding="wsHttpBinding"
                bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1"
                name="WSHttpBinding_IService1">
            </endpoint>
        </client>
        <services>
          <service name="WCFSessionManagement.Service1">
            <endpoint address="" binding="wsHttpBinding" contract="WCFSessionManagement.IService1" bindingConfiguration="WSHttpBinding_IService"></endpoint>
          </service>
        </services>
          <bindings>
            <wsHttpBinding>
              <binding name="WSHttpBinding_IService" messageEncoding="Text">
                <reliableSession enabled="true" />
                <security mode="None" />
              </binding>
              <binding name="WSHttpBinding_IService1" messageEncoding="Text">
                <reliableSession enabled="true" />
                <security mode="None" />
              </binding>
            </wsHttpBinding>
          </bindings>
            <behaviors>
                <serviceBehaviors>
                    <behavior>
                        <serviceMetadata httpGetEnabled="true" />
                        <serviceDebug includeExceptionDetailInFaults="true" />
                    </behavior>
                </serviceBehaviors>
            </behaviors>
            <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
        </system.serviceModel>
    </configuration>

    Best Regards,
    Amy Peng

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Monday, March 31, 2014 10:23 AM
    Moderator

All replies

  • Hi,

    First please try to set the following to ture to get more error information:

    <serviceDebug includeExceptionDetailInFaults="ture" />

    Then please try to enable the wcf tracing to find more cause.

    The following configuration taken from MSDN can be applied to enable tracing on your WCF service.

    <configuration>
      <system.diagnostics>
        <sources>
          <source name="System.ServiceModel"
                  switchValue="Information, ActivityTracing"
                  propagateActivity="true" >
            <listeners>
                 <add name="xml"/>
            </listeners>
          </source>
          <source name="System.ServiceModel.MessageLogging">
            <listeners>
                <add name="xml"/>
            </listeners>
          </source>
          <source name="myUserTraceSource"
                  switchValue="Information, ActivityTracing">
            <listeners>
                <add name="xml"/>
            </listeners>
          </source>
        </sources>
        <sharedListeners>
            <add name="xml"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="Error.svclog" />
        </sharedListeners>
      </system.diagnostics>
    </configuration>

    Also please try to post your service config file here, and I want to do a test in my side.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 24, 2014 10:16 AM
    Moderator
  • Hi Amy,

    I have hosted the WCF service in my web project itself. So, I have only web.config file. I have uploaded the complete project at URL :

    https://drive.google.com/file/d/0B6vvhyjkwQ8eZm91UUlMV1dsTTA/edit?usp=sharing
    Monday, March 24, 2014 3:56 PM
  • Hi,

    I have test your code, and I got your wsdl file, I found you have only used the basicHttpBinging in your service, but you have used the wsHttpBinging in the client, so the binding in the server and client side is mimatch. Then please try to delete your wsHttpBinding and the endpoint which uses the wsHttpBinding. Then also please try to modify your client as following:

     ServiceReference1.Service1Client obj = new ServiceReference1.Service1Client("BasicHttpBinding_IService1");

    Then the result:


    Best Regards,
    Amy Peng

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, March 25, 2014 5:18 AM
    Moderator
  • Hi Amy,

    Yes rightly pointed, I have used wsHttpBinding on the client as I wanted to use PerSession Instance Management.

    Can you please let me know how can I use the wsHttpBinding instead of BasicHttpBinding.

    Tuesday, March 25, 2014 2:39 PM
  • Hi,

    Please try to add the following in your web config file, then delelte your client config, and add the service reference again, then it should work.

      <services>
            <service name="WCFSessionManagement.Service1">
              <endpoint address="" binding="basicHttpBinding" contract="WCFSessionManagement.IService1"></endpoint>
              <endpoint address="sd" binding="wsHttpBinding" contract="WCFSessionManagement.IService1"></endpoint>
            </service>
     </services>

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 26, 2014 2:37 AM
    Moderator
  • Hi Amy,

    As I have added the WCF service in my web project, I have only the web.config file. In the web.config file, I only have the 'wsHttpBinding' endpoint now, then deleted the service reference and added it again. By doing so, the basicHttpBinding was again created. Running the project again throws the same error. Please advise.

    Wednesday, March 26, 2014 4:03 PM
  • Hi,

    The following is my web.config file, it works well:

     <system.diagnostics>
        <sources>
          <source name="System.ServiceModel"
                  switchValue="Information, ActivityTracing"
                  propagateActivity="true" >
            <listeners>
              <add name="xml"/>
            </listeners>
          </source>
          <source name="System.ServiceModel.MessageLogging">
            <listeners>
              <add name="xml"/>
            </listeners>
          </source>
          <source name="myUserTraceSource"
                  switchValue="Information, ActivityTracing">
            <listeners>
              <add name="xml"/>
            </listeners>
          </source>
        </sources>
        <sharedListeners>
          <add name="xml"
               type="System.Diagnostics.XmlWriterTraceListener"
               initializeData="Error.svclog" />
        </sharedListeners>
      </system.diagnostics>
      
        <system.web>
            <compilation debug="true" targetFramework="4.0" />
        </system.web>
    
        <system.serviceModel>
       
        <client>
            <endpoint address="http://localhost:49326/Service1.svc" binding="wsHttpBinding"
                bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1"
                name="WSHttpBinding_IService1">
            </endpoint>
        </client>
        <services>
          <service name="WCFSessionManagement.Service1">
            <endpoint address="" binding="wsHttpBinding" contract="WCFSessionManagement.IService1" bindingConfiguration="WSHttpBinding_IService"></endpoint>
          </service>
        </services>
          <bindings>
            <wsHttpBinding>
              <binding name="WSHttpBinding_IService" messageEncoding="Text">
                <reliableSession enabled="true" />
                <security mode="None" />
              </binding>
              <binding name="WSHttpBinding_IService1" messageEncoding="Text">
                <reliableSession enabled="true" />
                <security mode="None" />
              </binding>
            </wsHttpBinding>
          </bindings>
            <behaviors>
                <serviceBehaviors>
                    <behavior>
                        <serviceMetadata httpGetEnabled="true" />
                        <serviceDebug includeExceptionDetailInFaults="true" />
                    </behavior>
                </serviceBehaviors>
            </behaviors>
            <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
        </system.serviceModel>
    </configuration>

    Best Regards,
    Amy Peng

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Monday, March 31, 2014 10:23 AM
    Moderator