Content Type application/soap+xml; charset=utf-8 was not supported by service

后端 未结 17 2325
长发绾君心
长发绾君心 2020-12-15 02:54

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

相关标签:
17条回答
  • 2020-12-15 03:19

    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>
    
    0 讨论(0)
  • 2020-12-15 03:19

    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; }
    
    }
    
    0 讨论(0)
  • 2020-12-15 03:21

    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>
    
    0 讨论(0)
  • 2020-12-15 03:26

    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" >
    
    0 讨论(0)
  • 2020-12-15 03:26

    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

    0 讨论(0)
提交回复
热议问题