定义 baseURL 和 EndPoint
Defining baseURL and EndPoint
我用三种方法做了一个WCF:
[ServiceContract]
public interface IService1
{
[OperationContract]
String devolverPisosA();
[OperationContract]
String devolverPisosV();
[OperationContract]
String devolverNoticias();
}
我需要在 Web.config 文件中定义 baseAddress 和 EndPoint 但是我不知道如何:
我正在尝试这个(和一些变体)但是这不起作用...(在 system.serviceModel 之间)
<services>
<service
name="ProyectoJosephWCF.Service1">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/Iservice1/"/>
</baseAddresses>
</host>
<endpoint address="devolverPisoA"
binding="wsHttpBinding"
contract="ProyectoJosephWCF.Service1" />
<endpoint address="devolverPisoV"
binding="wsHttpBinding"
contract="ProyectoJosephWCF.Service1" />
<endpoint address="devolverNoticias"
binding="wsHttpBinding"
contract="ProyectoJosephWCF.Service1" />
</service>
</services>
已编辑:如果我之前没有定义 baseAddress 和端点(使用创建项目时创建的默认配置),并且我启动了 Services1.svc,我可以得到结果 json 通过测试 windows 但我不能(或者至少我不知道如何)从 Android 获得 JSON 结果(通过 Retrofit)。我以为我配置了 Retrofit(baseAddress 和 Endpoint 值错误),所以我决定自己设置这些值......
为此,我之前在 Web.config 中设置了代码,但我也无法访问它们...
此外,我想通过 Mozilla(我的意思是在浏览器中)获得 JSON 结果,因为有人告诉我这可以帮助我理解我使用的 baseAddress 和 Endpoint...
EDITED2:行为设置为:
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
并且仍然无法通过 android 或浏览器获得结果...
您需要设置 httpGetEnabled="true"
以使 WSDL 可用,如下所示
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
在您的服务声明中包含相同的行为配置,例如
<service name="ProyectoJosephWCF.Service1"
behaviorConfiguration="NewBehavior">
有关详细信息,请参阅 serviceMetadata。
终于……有需要的可以看看
<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>
并且:
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "devolverPisoA")]
List<pisosAlquiler> devolverPisosA();
我用三种方法做了一个WCF:
[ServiceContract]
public interface IService1
{
[OperationContract]
String devolverPisosA();
[OperationContract]
String devolverPisosV();
[OperationContract]
String devolverNoticias();
}
我需要在 Web.config 文件中定义 baseAddress 和 EndPoint 但是我不知道如何:
我正在尝试这个(和一些变体)但是这不起作用...(在 system.serviceModel 之间)
<services>
<service
name="ProyectoJosephWCF.Service1">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/Iservice1/"/>
</baseAddresses>
</host>
<endpoint address="devolverPisoA"
binding="wsHttpBinding"
contract="ProyectoJosephWCF.Service1" />
<endpoint address="devolverPisoV"
binding="wsHttpBinding"
contract="ProyectoJosephWCF.Service1" />
<endpoint address="devolverNoticias"
binding="wsHttpBinding"
contract="ProyectoJosephWCF.Service1" />
</service>
</services>
已编辑:如果我之前没有定义 baseAddress 和端点(使用创建项目时创建的默认配置),并且我启动了 Services1.svc,我可以得到结果 json 通过测试 windows 但我不能(或者至少我不知道如何)从 Android 获得 JSON 结果(通过 Retrofit)。我以为我配置了 Retrofit(baseAddress 和 Endpoint 值错误),所以我决定自己设置这些值...... 为此,我之前在 Web.config 中设置了代码,但我也无法访问它们...
此外,我想通过 Mozilla(我的意思是在浏览器中)获得 JSON 结果,因为有人告诉我这可以帮助我理解我使用的 baseAddress 和 Endpoint...
EDITED2:行为设置为:
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
并且仍然无法通过 android 或浏览器获得结果...
您需要设置 httpGetEnabled="true"
以使 WSDL 可用,如下所示
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
在您的服务声明中包含相同的行为配置,例如
<service name="ProyectoJosephWCF.Service1"
behaviorConfiguration="NewBehavior">
有关详细信息,请参阅 serviceMetadata。
终于……有需要的可以看看
<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>
并且:
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "devolverPisoA")]
List<pisosAlquiler> devolverPisosA();