簡體   English   中英

SILVERLIGHT WCF問題:內容類型application / soap + xml; charset = utf-8已發送到需要text / xml的服務;

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

好的,我真的很不走運……我在StackOverflow上可以找到的所有幫助都沒有解決我的問題。 拜托...。這不是重復的。 這是不同的,因為

a)我的服務器是Windows應用程序,未使用“ APP.CONFIG”文件設置WCF綁定。 我以編程方式設置它:

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();

這可以正常工作,主機可以很好地打開。

b)我的客戶端是Silverlight應用程序,而不是這里的所有其他ASP.NET應用程序。 我連接服務器不是使用WEBCONFIG文件,而是通過添加服務引用(在服務引用==> ADD服務引用上單擊鼠標右鍵)。 添加之后,似乎沒什么問題,並且生成了一個不錯的ClientConfig文件,如下所示:

<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>

我使用的WCF Servier客戶端界面如下:

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; }
    }
}

問題

添加服務引用后,未創建接口對象! 我不知道為什么...我打開了WCF錯誤跟蹤(來自app.config文件),並收到以下錯誤:

內容類型application / soap + xml; charset = utf-8已發送到需要text / xml的服務; charset = utf-8。 客戶端和服務綁定可能不匹配。

使用以下堆棧跟蹤

System.ServiceModel.Channels.HttpInput.ThrowHttpProtocolException(字符串消息,HttpStatusCode statusCode,字符串statusDescription)System.ServiceModel.Channels.HttpInput.ParseMessageAsyncResult.BeginParse()System.ServiceModel.Channels.HttpInput.BeginParseIncomingMessage(HttpRequestMessage httpRequestMessage,AsyncCallback回調,對象狀態)System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.BeginProcessInboundRequest(ReplyChannelAcceptor replyChannelAcceptor,Action dequeuedCallback,AsyncCallback回調,對象狀態)System.ServiceModel.Channels.HttpChannelListener 1.HttpContextReceivedAsyncResult ()System.ServiceModel.Channels.HttpChannelListener BeginHttpContextReceived(HttpRequestContext上下文,Action acceptorCallback,AsyncCallback回調,對象狀態)System.ServiceModel.Channels.SharedHttpTransportManager.EnqueueContext(IAsyncResult listenerContextResult)System.ServiceModel.Channels.SharedHttpTransportManager.OnGetContextCo 重新(IAsyncResult listenerContextResult)System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult結果)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)

最奇怪的部分

最奇怪的部分是,如果我刪除了其他兩個接口,但只允許使用“ GetServerTimeUTC”接口(如該接口所示,僅以UTC格式獲取服務器時間)。 服務引用對象創建良好!

兩個客戶端服務器綁定都是BasicHTTPBindings,沒什么特別的。

我還注意到大約一個月前,我切換到VS2013之前,它運行良好。 切換后大約一個月,我沒有使用WCF模塊,因此它可能會或可能不會相關..如果有人看到任何類似的東西,請抬起頭來。

我真的很走運...任何幫助,謝謝大家!

返回字典類型錯誤。 有關使用字典, 請參閱此

不幸的是我英語說得不好

請更改此代碼:

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

使用此代碼:

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

然后:

 [OperationContract]
           UseDictionary GetTagList();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 wcf +響應消息的內容類型text / html與綁定的內容類型不匹配(application / soap + xml; charset = utf-8) WCF錯誤:(415)內容類型&#39;application / x-www-form-urlencoded&#39;不是預期類型&#39;application / soap + xml; 字符集= UTF-8&#39; WCF成員資格提供程序引發錯誤:內容類型&#39;application / json; charset = utf-8&#39;不是預期的類型&#39;application / soap + xml; 字符集= UTF-8&#39; 收到錯誤消息,客戶端發現響應內容類型為&#39;text / html; charset = utf-8”,但預期為“ application / soap + xml”? 響應消息的內容類型 application/xml;charset=utf-8 與綁定的內容類型(text/xml; charset=utf-8)不匹配,WCF 更改WCF服務以接受內容類型“ application / xml; charset = utf-8” 無法處理該消息,因為內容類型“ application / xml”不是預期的類型“ application / soap + xml”; 字符集= utf-8&#39; 響應消息的內容類型application / xml; charset = utf-8與綁定的內容類型不匹配(text / xml; charset = utf-8) WCF SOAP服務無法處理該消息,因為它發送多部分消息並且需要&#39;text / xml; charset = utf-8&#39; HTTP 415 無法處理消息,因為內容類型為“application/json; charset=utf-8&#39; 不是預期的類型 &#39;text/xml; 字符集=utf-8&#39;
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM