Como posso usar um serviço WCF?
Quando crio um novo serviço WCF, posso criar um novo método como este:
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "TryThis", ResponseFormat = WebMessageFormat.Json)]
string TryThis();
ma função que retorna uma string simple
Eu posso usá-lo com o cliente de teste WCF e isso funciona. Mas quando quero acessar meu serviço com o Chrome, o carteiro ou meu aplicativo Android, não consigo.
Tentei com teses urls:
http://localhost:54792/Service1.svc/TryThis
http://tempuri.org/IService1/TryThis
Quando eu uso 'http: // localhost: 54792 / Service1.svc 'Eu tenho a página inicial, então está tudo bem. Mas não tenho acesso a nenhum método do meu serviço.
O erro é um erro 400. mas não tenho nenhuma mensagem que indique onde está esse erro. Não sei se esta é a configuração do meu servidor IIS, se este é o meu serviço. Estou totalmente bloqueado.
Este é meuweb.config
:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.7.1" />
<httpRuntime targetFramework="4.7.1"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
PS: Eu já vi este post: "Como posso acessar os serviços WCF usando uma Referência da Web? "mas isso não me ajudou.