SILVERLIGHT WCF 问题:内容类型 application/soap+xml; charset=utf-8 被发送到需要 text/xml 的服务;
Posted
技术标签:
【中文标题】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; 【发布时间】:2015-05-25 10:11:12 【问题描述】:好的,我在这方面真的不走运......我在 *** 上找到的所有帮助都没有解决我的问题。请......这不是重复的。这是不同的,因为
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 文件,而是通过添加服务参考(右键单击服务参考 ==> 添加服务参考)。添加后似乎没有出错,并生成了一个不错的 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 Client界面如下:
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 的服务;字符集=utf-8。客户端和服务绑定可能不匹配。
使用以下堆栈跟踪
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 回调,对象状态) System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.BeginProcessInboundRequest(ReplyChannelAcceptor replyChannelAcceptor,Action dequeuedCallback,AsyncCallback 回调,对象状态) 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.OnGetContextCore(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 模块上工作,所以它可能相关也可能不相关.. 如果有人看到类似的东西,请提醒一下。
我真的很不走运......任何帮助,非常感谢!
【问题讨论】:
【参考方案1】:返回字典类型错误。 对于使用字典,See This
【讨论】:
您的意思是添加数据合同和数据成员标签吗?我试过了......不,没有用 否,为了更好地理解这个问题,请看以下地址:***.com/questions/2160052/…【参考方案2】:很遗憾,我的英语说得不好
请更改此代码:
[OperationContract]
Dictionary<string, clsWCFTag> GetTagList();
使用此代码:
public class UseDictionary
[DataMemeber]
public string KeyItemget;set;
[DataMemeber]
public clsWCFTag ValueItemget;set;
然后:
[OperationContract]
UseDictionary GetTagList();
【讨论】:
以上是关于SILVERLIGHT WCF 问题:内容类型 application/soap+xml; charset=utf-8 被发送到需要 text/xml 的服务;的主要内容,如果未能解决你的问题,请参考以下文章
跨域 WCF - Silverlight 配置错误 a:ActionNotSupported