【发布时间】:2014-03-01 22:14:00
【问题描述】:
我根据 stackoverflow 的这篇文章构建了一个 wcf 服务:How to send xml via post with wcf 但我收到了这个错误:
远程服务器返回错误:(415)无法处理消息 因为内容类型“application/xml”不是预期的类型 '文本/xml; charset=utf-8'..
我认为我的 Web.config 有问题,我将其发布在这里:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="BridgeService.BridgeData" behaviorConfiguration="RESTBehavior">
<endpoint address="" binding="basicHttpBinding" contract="BridgeService.IBridgeData" behaviorConfiguration="MyEndpointBehavior">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:10912/Vishi/BridgeService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="RESTBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="MyEndpointBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
这是界面:
[ServiceContract]
public interface IBridgeData
{
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "InsertData",
RequestFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare)]
string InsertData(transport_xml transport_xml);
}
并且调用与 Stackoverflow 的引用帖子相同。请帮我。提前致谢!!
【问题讨论】:
标签: wcf