我有这样的 WCF 服务:
[ServiceContract]
public class SomeService
{
[WebInvoke(UriTemplate = "/test", Method = "POST")]
public string Test()
{
using (var reader = OperationContext.Current.RequestContext.RequestMessage.GetReaderAtBodyContents())
{
var content = reader.ReadOuterXml().Replace("<Binary>", "").Replace("</Binary>", "");
return content;
}
}
}
并且有一个这样的配置文件:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="Project.SomeService">
<endpoint address="" binding="webHttpBinding" contract="Project.SomeService"
bindingConfiguration="webHttpBinding_SomeService" behaviorConfiguration="endpointBehavior_SomeService" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webHttpBinding_SomeService">
<security mode="None"></security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="endpointBehavior_SomeService">
<webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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 multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
但是当我使用 fiddler 和这个 url 来调用它时POST
:
http://localhost:1111/SomeService.svc/Test
与身体:
asdasd
它反而返回YXNkYXNk
,为什么会这样?
我的代码是 C#,框架 4,在 VS2010Pro 中构建。
请帮忙。提前致谢。