C# SILVERLIGHT WCF问题:内容类型应用程序/soap+;xml;charset=utf-8已发送到需要text/xml的服务;
好吧,这一次我真的很不走运。。。关于StackOverflow的所有帮助都没有解决我的问题。请。。。。这不是复制品。这是不同的,因为 a) 我的服务器是一个Windows应用程序,它不使用“APP.CONFIG”文件设置WCF绑定。我按程序设置它:C# SILVERLIGHT WCF问题:内容类型应用程序/soap+;xml;charset=utf-8已发送到需要text/xml的服务;,c#,wcf,silverlight,C#,Wcf,Silverlight,好吧,这一次我真的很不走运。。。关于StackOverflow的所有帮助都没有解决我的问题。请。。。。这不是复制品。这是不同的,因为 a) 我的服务器是一个Windows应用程序,它不使用“APP.CONFIG”文件设置WCF绑定。我按程序设置它: string baseHTTPAddress = "http://localhost:8724/Processor"; //Instantiate ServiceHost host = new ServiceHost(typeof(
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();
string baseHTTPAddress=”http://localhost:8724/Processor";
//实例化ServiceHost
主机=新服务主机(typeof(clsType),新Uri(baseHTTPAddress));
//添加服务元数据行为
ServiceMetadataBehavior smb=新ServiceMetadataBehavior();
smb.HttpGetEnabled=true;
host.Description.Behaviors.Add(smb);
//将端点添加到主机
AddServiceEndpoint(typeof(iclsType),new BasicHttpBinding(),“”);
host.AddServiceEndpoint(typeof(IPolicyRetriever)、新WebHttpBinding()、新Uri(“http://localhost:8724/添加(新的WebHttpBehavior());
host.AddServiceEndpoint(typeof(IMetadataExchange),MetadataExchangeBindings.CreateMexHttpBinding(),新Uri(“http://localhost:8724/mex"));
ServiceDebugBehavior=host.Description.Behaviors.Find();
如果(behavior!=null)behavior.IncludeExceptionDetailInFaults=true;
else host.Description.Behaviors.Add(新的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>
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施维雅客户端界面如下:
<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>
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; }
}
}
使用系统;
使用系统集合;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.ServiceModel;
使用系统线程;
使用System.Threading.Tasks;
使用System.IO;
使用System.Runtime.Serialization;
命名空间中心
{
[服务合同]
公共接口IPProcessorClientWCF
{
[经营合同]
DateTime GetServerTimeUTC();
[经营合同]
字典GetTagList();
[经营合同]
列出GetRawValues(DateTime FromDT、DateTime ToDT、int MinTimeBetween SamplesInms、字符串标记名);
}
公共类clsWCFTag
{
公共clsWCFTag()
{
}
公共clsWCFTag(字符串标记名、字符串参数、字符串度量单位、字符串描述、字符串公司、字符串工厂、字符串区域、字符串单位)
{
this.TagName=标记名;
此参数=参数;
this.UnitOfMeasure=测量单位;
这个。描述=描述;
这个。公司=公司;
这个。植物=植物;
这个。面积=面积;
这个。单位=单位;
}
公共字符串标记名{get;set;}
公共字符串参数{get;set;}
公共字符串度量单位{get;set;}
公共字符串说明{get;set;}
公共字符串DADatabaseLocation{get;set;}
公共字符串ParsedDatabaseLocation{get;set;}
公共字符串{get;set;}
公共字符串工厂{get;set;}
公共字符串区域{get;set;}
公共字符串单元{get;set;}
}
公共类clsWCFSample
{
公共clsWCFSample()
{
}
公共clsWCFSample(日期时间TSUTC、字符串值、字符串质量)
{
this.TSUTC=TSUTC;
这个。值=值;
这个。质量=质量;
}
公共日期时间TSUTC{get;set;}
公共字符串值{get;set;}
公共字符串质量{get;set;}
}
}
问题
添加服务引用后,接口对象没有创建!
我不知道为什么。。。我打开了WCF错误跟踪(从app.config文件),并出现以下错误:
内容类型应用程序/soap+xml;charset=utf-8已发送到需要text/xml的服务;字符集=utf-8。客户端和服务绑定可能不匹配
使用以下堆栈跟踪
System.ServiceModel.Channel.HttpInput.ThrowHttpProtocolException(字符串消息、HttpStatusCode状态代码、字符串状态描述)
System.ServiceModel.Channels.HttpInput.ParseMessageAsyncResult.BeginParse()
System.ServiceModel.Channels.HttpInput.BeginParseIncomingMessage(HttpRequestMessage HttpRequestMessage,异步回调,对象状态)
System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.BeginProcessInboundRequest(ReplyChannelAcceptor ReplyChannelAcceptor,Action dequeuedCallback,AsyncCallback回调,对象状态)
System.ServiceModel.Channels.HttpChannelListener1.HttpContextReceivedAsyncResult
1.ProcessHttpContextAsync()
System.ServiceModel.Channels.HttpChannelListener`1.BeginHttpContextReceived(HttpRequestContext上下文、Action Acceptor回调、AsyncCallback回调、对象状态)
System.ServiceModel.Channel.SharedHttpTransportManager.EnqueueContext(IAsyncResult listenerContextResult)
System.ServiceModel.Channel.SharedHttpTransportManager.OnGetContextCore(IAsyncResult listenerContextResult)
System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult结果)
System.Net.LazyAsyncResult.Complete(IntPtr userToken)
System.Net.ListenarSyncResult.IOCompleted(ListenarSyncResult asyncResult,UInt32错误代码,UInt32个字节)
System.Threading.\u IOCompletionCallback.PerformiCompletionCallback(UInt32错误代码,UInt32字节,本机重叠*pOVERLAP)
Th
[OperationContract]
UseDictionary GetTagList();