0
我有一个WCF服务是这样的:WCF Restful Service:正文编码自动更改?
[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>
但是,当我打电话使用招用这个网址与POST
方法是:
http://localhost:1111/SomeService.svc/Test
与身体:
asdasd
它会返回YXNkYXNk
而不是,为什么会这样?
我的代码是在C#中,框架4,内置VS2010Pro。
请帮忙。提前致谢。
什么是不明确的_提供body_?我使用Fiddler并将'asdasd'放在_body_字段中,或者它是服务器端_on如何检索body_?请帮忙。 –
@JohnIsaiahCarmona:在我面前没有提琴手,我不知道有什么选择。但请参阅我的编辑 - 基本上Fiddler和服务器都将它视为*二进制*数据,但是您不是从base64表示中解码出来的。 –
非常感谢!有用。 –