我创建了一个WCF服务,我想是因为我启动Services1.svc.cs
测试的客户端是打开的。然后调用我的方法,并在JSON (测试的客户端窗口)中获得适当的数据。
但是当我启动所有proyect时,我不知道如何访问JSON的url,以便通过Mozilla检查JSON的数据.我需要这个url来知道如何设置Retrofit的值(android)来消费WCF。
-Service1.svc.cs--
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "pisosA/")]
public String devolverPisosA()
{
List<pisosAlquiler> consultaPA = (from piso in contexto.pisosAlquiler
select piso).ToList();
string json = JsonConvert.SerializeObject(consultaPA);
return json;
}
-服务
[OperationContract]
String devolverPisosA();
谢谢朋友们..。
编辑:
我将在Android中使用这个WCF,但它并不重要。首先,我需要通过浏览器获取查看JSON的url。然后,我必须用baseURL和get方法来设置Retrofit,但是我会(我希望)在前面的url中得到它们。
发布于 2016-07-11 07:51:29
井,
我终于找到解决办法了。愚蠢的那个..。当我有指定时,我不需要序列化数据结果。只需返回对象列表..。
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "pisosA")]
public String devolverPisosA()
{
List<pisosAlquiler> consultaPA = (from piso in contexto.pisosAlquiler
select piso).ToList();
return consultaPA;
}
<system.serviceModel>
<services>
<service name="ProyectoJosephWCF.Service1" behaviorConfiguration="ServiceBehavior">
<endpoint binding="webHttpBinding"
contract="ProyectoJosephWCF.IService1"
behaviorConfiguration="webHttp"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<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="false"/>
</behavior>
</serviceBehaviors>
然后,我可以使用http://localhost:8080/Service1.svc/pisosA浏览器查看JSON结果。
谢谢各位朋友。
https://stackoverflow.com/questions/37662259
复制相似问题