[英]wcf + The content type text/html of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8)
[英]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.