配置Web.config以发布WCF服务

问题描述 投票:0回答:1

我正在从asmx web服务跳转到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

ımynewservice.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错误。

谁能找到我的错误并帮助一个人出去?

提前致谢

vb.net wcf iis https web-config
1个回答
1
投票

一般来说,我添加两个服务端点地址来通过http和https托管服务。 WCF Service not hitting from postman over https 或者以下简化配置。

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior>
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>
<bindings>
  <webHttpBinding>
    <binding name="https">
      <security mode="Transport">
        <transport clientCredentialType="None"></transport>
      </security>
    </binding>
  </webHttpBinding>
</bindings>
<protocolMapping>
  <add binding="webHttpBinding" scheme="http" />
  <add binding="webHttpBinding" scheme="https" bindingConfiguration="https" />
</protocolMapping>    
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

如果有什么我可以帮忙,请随时告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.