我使用 c#4.0 和 wcf 4.0 创建了一个 WCF 服务,它在本地运行良好。使用 WCf 测试客户端和控制台应用程序作为客户端进行了测试。但是在部署服务之后,我也做了同样的事情,但它给出了以下错误。我不知道我做错了什么......
内容类型 text/html;响应消息的 charset=UTF-8 与绑定的内容类型不匹配 (text/xml; charset=utf-8)。
如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法。
响应的前 1024 个字节是:
' #content{ 字体大小:0.7em; 垫底:2em;MARGIN-LEFT: 30px}BODY{MARGIN-TOP: 0px; 左边距:0px;颜色:#000000;字体家族:Verdana;背景颜色:白色}P{边距顶部:0px;边距底部:12px;颜色:#000000;FONT-FAMILY: Verdana}PRE{BORDER-RIGHT: #f0f0e0 1px solid; 填充右:5px;边框顶部:#f0f0e0 1px 实心;边距顶部:-5px;填充左:5px;字体大小:1.2em;填充底部:5px;左边界:#f0f0e0 1px 实心;填充顶部:5px;边框底部:#f0f0e0 1px 实心;FONT-FAMILY:Courier New;背景颜色:#e5e5cc}.heading1{MARGIN-TOP:0px;填充左:15px;字重:正常;字体大小:26px;边距底部:0px;填充底部:3px;左边距:-30px;宽度:100%;颜色:#ffffff;填充顶部:10px;字体家族:Tahoma;Background-COLOR: #003366}.intro{MARGIN-LEFT: -15px} 测试服务服务器堆栈跟踪:
在 System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest 请求,HttpWebResponse 响应,HttpChannelFactory 1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan 超时) 在 System.ServiceModel.Channels.RequestChannel.Request(消息消息,TimeSpan 超时) 在 System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan 超时) 在 System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔单向,ProxyOperationRuntime 操作,Object[] 输入,Object[] 输出,TimeSpan 超时) 在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime 操作)1 factory, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory
在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage 消息)
调用服务::
public static void Main(string[] args)
{
TestClient user = new TestClient();
string id = "rSmith";
string u = user.GetUserName(id);
user.Close();
Console.WriteLine("The User you Requested is "+ u+" .");
}
服务 WebConfig。
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="NameSoap"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
allowCookies="false"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536"
maxBufferPoolSize="524288"
maxReceivedMessageSize="65536"
messageEncoding="Text"
textEncoding="utf-8"
transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32"
maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName"
algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<mexHttpBinding>
<binding name="NewBinding1"/>
</mexHttpBinding>
</bindings>
<!--<client/>-->
<services>
<service behaviorConfiguration="MyServiceTypebehaviors"
name="Test">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="UserNameSoap"
bindingNamespace="https:/abc.com/Services/Test/"
contract="Test.ITest" />
<endpoint address="mex"
binding="mexHttpBinding"
bindingConfiguration="NewBinding1"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypebehaviors">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false"
multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
客户端配置文件
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ITest" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://abc.com/Services/Test/Test.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ITest"
contract="DevService.ITest"
name="BasicHttpBinding_ITest" />
</client>
</system.serviceModel>