2014-03-01 90 views
0

我根據這個帖子計算器內置一個WCF服務:How to send xml via post with wcf,但我收到此錯誤:通過郵寄發送XML使用WCF,但得到錯誤415

The remote server returned an error: (415) Cannot process the message because the content type 'application/xml' was not the expected type 'text/xml; charset=utf-8'..

我覺得有somethimg錯我的網站。配置我在這裏張貼:

<?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); 
} 

和Ca lling與Stackoverflow引用的帖子相同。請幫幫我。提前致謝!!

回答

1

使用您必須的WebHttpBinding一個休息行爲。試着改變它。

1

將您的綁定更改爲webHttpBinding

binding="basicHttpBinding" 

,並確保當你的要求,不要忘了添加Content-Type,如:

Content-Type: application/xml;charset=utf-8