Я делаю переход с asmx webservice на WCF (в основном для поддержки работы с Json)
Я дошел до того, что Сервис работает (только локально) только в http, но не в https. (На моем сервере не работает ни один, так как сервер заставляет https)
Вот мои простые коды:
MyNewService.VB
Public Class MyNewService
Implements IMyNewService
Public Sub New()
End Sub
Public Function GetResults() As List(Of Person) Implements IMyNewService.GetResults
Dim rslt As New List(Of Person)
rslt.Add(New Person("Mike", "Anderson", 40))
rslt.Add(New Person("Drew", "Carry", 38))
rslt.Add(New Person("John", "Tavares", 43))
Return rslt
End Function
End Class
IMyNewService.VB
<ServiceContract()>
Public Interface IMyNewService
<OperationContract()>
<WebInvoke(Method:="GET", RequestFormat:=WebMessageFormat.Json, ResponseFormat:=WebMessageFormat.Json, UriTemplate:="getPeople")>
Function GetResults() As List(Of Person)
End Interface
<DataContract()>
Public Class Person
<DataMember()>
Public Property FirstName() As String
<DataMember()>
Public Property LastName() As String
<DataMember()>
Public Property Age() As Integer
Public Sub New(firstname As String, lastname As String, age As Integer)
Me.FirstName = firstname
Me.LastName = lastname
Me.Age = age
End Sub
End Class
Web.Config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2"/>
<pages>
<namespaces>
<add namespace="System.Runtime.Serialization" />
<add namespace="System.ServiceModel" />
<add namespace="System.ServiceModel.Web" />
</namespaces>
</pages>
</system.web>
<system.serviceModel>
<protocolMapping>
<add scheme="http" binding="webHttpBinding"/>
</protocolMapping>
<behaviors>
<serviceBehaviors>
<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>
<endpointBehaviors>
<behavior>
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
Итак, сейчас я могу запустить:
http://localhost:61028/MyNewService.svc/getPeople
и я правильно получаю:
[{"Age":40,"FirstName":"Yoni","LastName":"Sudwerts"},{"Age":38,"FirstName":"Joshua","LastName":"Kishinef"},{"Age":43,"FirstName":"Saul","LastName":"Kaye"}]
Но если я бегу:
https://localhost:44386/MyNewService.svc/getPeople
Я получаю ошибку 404.
Может кто-нибудь найти мою ошибку и помочь парню?
Заранее спасибо