Content Type text/xml; charset=utf-8 was not supported by service

前端 未结 10 1748
北海茫月
北海茫月 2020-12-01 09:59

I have a problem with a WCF service. I have a console application and I need to consume the service without using app.config, so I had to set the endpoint, etc. by code. I d

相关标签:
10条回答
  • 2020-12-01 10:29

    Do not forget check the bindings-related code too. So if you wrote:

    BasicHttpBinding binding = new BasicHttpBinding();
    

    Be sure that all your app.config files contains

    <endpoint address="..."
              binding="basicHttpBinding" ...
    

    not the

    <endpoint address="..."
              binding="wsHttpBinding" ...
    

    or so.

    0 讨论(0)
  • 2020-12-01 10:30

    I was also facing the same problem recently. after struggling a couple of hours,finally a solution came out by addition to

    Factory="System.ServiceModel.Activation.WebServiceHostFactory"
    to your SVC markup file. e.g.
    ServiceHost Language="C#" Debug="true" Service="QuiznetOnline.Web.UI.WebServices.LogService" 
    Factory="System.ServiceModel.Activation.WebServiceHostFactory" 
    

    and now you can compile & run your application successfully.

    0 讨论(0)
  • 2020-12-01 10:30

    I had this error and all the configurations mentioned above were correct however I was still getting "The client and service bindings may be mismatched" error.

    What resolved my error, was matching the messageEncoding attribute values in the following node of service and client config files. They were different in mine, service was Text and client Mtom. Changing service to Mtom to match client's, resolved the issue.

    <configuration>
      <system.serviceModel>
          <bindings>
               <basicHttpBinding>
                  <binding name="BasicHttpBinding_IMySevice" ... messageEncoding="Mtom">
                  ...
                  </binding>
               </basicHttpBinding>
          </bindings>
      </system.serviceModel>
    </configuration>
    
    0 讨论(0)
  • 2020-12-01 10:36

    I saw this problem today when trying to create a WCF service proxy, both using VS2010 and svcutil.

    Everything I'm doing is with basicHttpBinding (so no issue with wsHttpBinding).

    For the first time in my recollection MSDN actually provided me with the solution, at the following link How to: Publish Metadata for a Service Using a Configuration File. The line I needed to change was inside the behavior element inside the MEX service behavior element inside my service app.config file. I changed it from

    &lt;serviceMetadata httpGetEnabled="true"/>  
    to  
    &lt;serviceMetadata httpGetEnabled="true" policyVersion="Policy15"/>
    

    and like magic the error went away and I was able to create the service proxy. Note that there is a corresponding MSDN entry for using code instead of a config file: How to: Publish Metadata for a Service Using Code.

    (Of course, Policy15 - how could I possibly have overlooked that???)

    One more "gotcha": my service needs to expose 3 different endpoints, each supporting a different contract. For each proxy that I needed to build, I had to comment out the other 2 endpoints, otherwise svcutil would complain that it could not resolve the base URL address.

    0 讨论(0)
  • 2020-12-01 10:38

    Again, I stress that namespace, svc name and contract must be correctly specified in web.config file:

     <service name="NAMESPACE.SvcFileName">
        <endpoint contract="NAMESPACE.IContractName" />
      </service>
    

    Example:

    <service name="MyNameSpace.FileService">
    <endpoint contract="MyNameSpace.IFileService" />
    </service>
    

    (Unrelevant tags ommited in these samples)

    0 讨论(0)
  • 2020-12-01 10:41

    For anyone who lands here by searching:

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

    or some subset of that error:

    A similar error was caused in my case by building and running a service without proper attributes. I got this error message when I tried to update the service reference in my client application. It was resolved when I correctly applied [DataContract] and [DataMember] attributes to my custom classes.

    This would most likely be applicable if your service was set up and working and then it broke after you edited it.

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