我创建了一个WCF服务。这是工作正常,当我使用简单的.NET通过添加作为一个Web服务。但我想使它能够使用iPhone应用程序为JSON调用。为了测试我已经用它在.NET中使用JSON,但它不工作。
I have created a wcf service. That is working fine when i am using simply in .net by adding as a webservice. But i want to make it able to use for iPhone app as JSON call. For testing i have used it in .net with JSON but its not working.
我知道这样的问题之前问,我特地为这对我来说不能找到解决方案。
i know this kind of question is asked before, i have looked in for this cant find solution for me.
我的配置:
<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>
接口code:
[ServiceContract]
public interface IGolfPyramidService
{
[WebInvoke(UriTemplate = "/Test", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
[OperationContract]
string Test();
}
Myservice.cs code:
Myservice.cs code:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService : IMyService
{
public string Test()
{
return "success";
}
}
我想有可能使用URL格式像调用方法: http://example.com/MyService.svc/test
i want to make it possible to call the method using url format like : http://example.com/MyService.svc/test
如果你是初学者,那么这将引导您创建一个可以通过iOS和Android消耗JSON和XML的web服务。 http://www.$c$cproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide
if you are beginner then this will guide you create json and xml enabled web service which can be consumed by IOS and android. http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide