简体   繁体   中英

SILVERLIGHT WCF Issue: Content Type application/soap+xml; charset=utf-8 was sent to a service expecting text/xml;

Okay, I'm really out of luck on this one... All the help I can find on StackOverflow has NOT RESOLVED my problem. Pleasee.... this is not a duplicate. This is different because

a) My server is a Windows Application which does not set the WCF bindings using the 'APP.CONFIG' file. I set it programatically:

string baseHTTPAddress = "http://localhost:8724/Processor";

    //Instantiate ServiceHost
    host = new ServiceHost(typeof(clsType), new Uri(baseHTTPAddress));

    //Add Service MetaData Behaviour                    
    ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
    smb.HttpGetEnabled = true;
    host.Description.Behaviors.Add(smb);

    //Add Endpoint to Host
    host.AddServiceEndpoint(typeof(iclsType), new BasicHttpBinding(), "");
    host.AddServiceEndpoint(typeof(IPolicyRetriever), new WebHttpBinding(), new Uri("http://localhost:8724/")).Behaviors.Add(new WebHttpBehavior());
    host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), new Uri("http://localhost:8724/mex"));


    ServiceDebugBehavior behavior = host.Description.Behaviors.Find<ServiceDebugBehavior>();
    if (behavior != null) behavior.IncludeExceptionDetailInFaults = true;
    else host.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });

    host.Open();

This works fine, the host opens nicely.

b) My client is a Silverlight application, not an ASP.NET application like all the others here. I connect to the the server NOT Using a WEBCONFIG file, but by adding a SERVICE REFERENCE (Rightclick on service reference ==> ADD service reference). After adding it seems that nothing went wrong and a nice ClientConfig file is generated as follows:

<configuration>


<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IProcessorClientWCF" maxBufferSize="2147483647"
            maxReceivedMessageSize="2147483647">
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8724/Processor" binding="basicHttpBinding"
          bindingConfiguration="BasicHttpBinding_IProcessorClientWCF"
          contract="ServiceReference1.IProcessorClientWCF" name="BasicHttpBinding_IProcessorClientWCF" />
    </client>
  </system.serviceModel>
</configuration>

The WCF Servier Client interface which I use is as follows:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Serialization;

namespace Hub
{
    [ServiceContract]
    public interface IProcessorClientWCF
    {
        [OperationContract]
        DateTime GetServerTimeUTC();

        [OperationContract]
        Dictionary<string, clsWCFTag> GetTagList();

        [OperationContract]
        List<clsWCFSample> GetRawValues(DateTime FromDT, DateTime ToDT, int MinTimeBetweenSamplesInMS, string TagName);
    }


    public class clsWCFTag
    {        
        public clsWCFTag()
        {
        }

        public clsWCFTag(string TagName, string Parameter, string UnitOfMeasure, string Description, string Corporate, string Plant, string Area, string Unit)
        {
            this.TagName = TagName;
            this.Parameter = Parameter;
            this.UnitOfMeasure = UnitOfMeasure;
            this.Description = Description;
            this.Corporate = Corporate;
            this.Plant = Plant;
            this.Area = Area;
            this.Unit = Unit;
        }
        public string TagName { get; set; }
        public string Parameter { get; set; }
        public string UnitOfMeasure { get; set; }
        public string Description { get; set; }
        public string DADatabaseLocation { get; set; }
        public string ParsedDADatabaseLocation { get; set; }
        public string Corporate { get; set; }
        public string Plant { get; set; }
        public string Area { get; set; }
        public string Unit { get; set; }
    }
    public class clsWCFSample
    {
        public clsWCFSample()
        {
        }
        public clsWCFSample(DateTime TSUTC, string Value, string Quality)
        {
            this.TSUTC = TSUTC;
            this.Value = Value;
            this.Quality = Quality;
        }
        public DateTime TSUTC { get; set; }
        public string Value { get; set; }
        public string Quality { get; set; }
    }
}

The Problem

After I add the service reference, the interface objects WERE NOT Created! I have no Idea why... I turned on WCF Error tracing (from the app.config file) and got the following error:

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.

with the following stacktrace

System.ServiceModel.Channels.HttpInput.ThrowHttpProtocolException(String message, HttpStatusCode statusCode, String statusDescription) System.ServiceModel.Channels.HttpInput.ParseMessageAsyncResult.BeginParse() System.ServiceModel.Channels.HttpInput.BeginParseIncomingMessage(HttpRequestMessage httpRequestMessage, AsyncCallback callback, Object state) System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.BeginProcessInboundRequest(ReplyChannelAcceptor replyChannelAcceptor, Action dequeuedCallback, AsyncCallback callback, Object state) System.ServiceModel.Channels.HttpChannelListener 1.HttpContextReceivedAsyncResult 1.ProcessHttpContextAsync() System.ServiceModel.Channels.HttpChannelListener`1.BeginHttpContextReceived(HttpRequestContext context, Action acceptorCallback, AsyncCallback callback, Object state) System.ServiceModel.Channels.SharedHttpTransportManager.EnqueueContext(IAsyncResult listenerContextResult) System.ServiceModel.Channels.SharedHttpTransportManager.OnGetContextCo re(IAsyncResult listenerContextResult) System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) System.Net.LazyAsyncResult.Complete(IntPtr userToken) System.Net.ListenerAsyncResult.IOCompleted(ListenerAsyncResult asyncResult, UInt32 errorCode, UInt32 numBytes) System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

The weirdest part

The weirdest part is that if I remove the two other interfaces but only allow the 'GetServerTimeUTC' interface (This interface as it says, just obtains the server time in UTC format).. this works! the Service Reference Objects are nicely created!

Both Client Server Bindings are BasicHTTPBindings, nothing fancy.

I also notice that about a months ago before I switched to VS2013 it worked fine. I didn't work on the WCF module for about a month after the switch, so it may or may not be related.. just giving a heads up if anyone has seen anything similer.

I'm really out of luck here... any help, thanks a bunch!

Error In Return Dictionary Type. For Use Dictionary, See This

Unfortunately I do not speak English well

Please change this code:

 [OperationContract]
        Dictionary<string, clsWCFTag> GetTagList();

With this code:

public class UseDictionary
{
[DataMemeber]
public string KeyItem{get;set;}
[DataMemeber]
public clsWCFTag ValueItem{get;set;}
}

Then:

 [OperationContract]
           UseDictionary GetTagList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM