我创建了一个wcf服务.当我在.net中使用添加为web服务时,这工作正常.但我想让它能够用作iPhone应用程序作为JSON调用.为了测试,我已经在.net中使用它与JSON,但它无法正常工作.
我知道之前有过这样的问题,我一直在找这个找不到解决方案.
我的配置:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="servicebehavior">
<serviceMetadata httpsGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="endpointBehavior">
<enableWebScript />
<webHttp defaultBodyStyle="Wrapped" defaultOutgoingResponseFormat="Json" />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="MyService" behaviorConfiguration="servicebehavior">
<endpoint address=""
behaviorConfiguration="endpointBehavior"
binding="webHttpBinding"
contract="IMyService" />
</service>
</services>
Run Code Online (Sandbox Code Playgroud)
接口代码:
[ServiceContract]
public interface IGolfPyramidService
{
[WebInvoke(UriTemplate = "/Test", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
[OperationContract]
string Test();
}
Run Code Online (Sandbox Code Playgroud)
Myservice.cs代码:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService : IMyService
{
public string Test()
{
return …Run Code Online (Sandbox Code Playgroud)