错误:没有端点正在侦听…


WCF 和 HTTPS,错误:没有端点在侦听,这通常是由不正确的地址或 SOAP 操作引起的

我正在尝试配置 WCF 服务以通过 HTTPS 工作,但遇到了很多问题。

我正在使用自签名证书在我的开发服务器上实现 https,一切正常。 当我转移到生产环境时,所有 url 值都是使用服务器名称而不是我的网站地址来读取的。

我在 Web 服务器上向 HTTPS 添加了一个主机标头,这应该使我能够避免使用静态 wsdl 和 xsd,但事实并非如此。 如果没有静态值,所有 url 默认为服务器名称。

因此,我将服务配置为具有静态 wsdl 和 xsd 文件,这些文件的地址中都包含 https。 然后,我将这些文件复制到我的网站目录中,以便托管它们。 这些文件托管在我的网站内,并且所使用的地址都可以正确解析。

在我的 soad 地址的 wsdl 中,我有一个 https 值。 https 值导致错误。 当我用 http 替换 https 时,服务可以正常工作,但是当

我用wire shark检查了数据没有加密。 不好。
我怎样才能让它发挥作用?

我有一个测试项目可以提交进行测试。
这是我收到的错误:

There was no endpoint listening at https://MYSERVICE/GpTest/Service1.svc that could accept the message.
This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found
Server stack trace:
   at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at TestWcfHttps1Caller.ServiceReference1.IService1.DoAddition(Int32 value1, Int32 value2)
   at TestWcfHttps1Caller.ServiceReference1.Service1Client.DoAddition(Int32 value1, Int32 value2) in C:\www\releases\Test\WCF\TestWcfHttps1Caller\Service References\ServiceReference1\Reference.cs:line 123
   at TestWcfHttps1Caller._Default.Page_Load(Object sender, EventArgs e) in C:\www\releases\Test\WCF\TestWcfHttps1Caller\Default.aspx.cs:line 15
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

解决方案1

我成功了,它结合了三种不同的解决方案

1.启用HTTPS主机头
2.启用静态wsdl和xsd文件
3.配置web.config

因此,要为 WCF 启用 HTTPS,我必须

1.创建静态wsdl和xsd文件

好吧怎么办?
1.1 点击 ?wsdl 链接并另存为 .wsdl 文件类型。 修改文件,将soad地址改为https。 您将从您的开发服务器链接到此文件,因为您的实时服务器很可能有一个指向服务器名称的链接,而不是您实际想要使用的 URL
1.2 在 .wsdl 文件中为 wsdl 中的每个 xsd 链接创建一个 .xsd 文件(即:xsd0.xsd、xsd1.xsd、xsd2.xsd)
1.3 更新 wsdl 文件和 xsd 文件中对 xsd 文档的所有引用,以使用您创建的新 xsd 文件。 使用您要使用的 url 指向托管值,所有地址现在都应该使用 https
1.3 将所有这些文件托管在 Web 应用程序的根目录中,并测试每个 url 是否正确解析
1.4 注意:每次对服务进行更改时,您都需要以这种方式重建所有静态文件

2. 在实时 IIS 服务器上启用 HTTPS 主机头(没有 GUI,必须使用命令行)

3.修改服务Web配置以在以下属性中包含传输安全模式和HTTPS(在下面的web.config中找到“https”)

这是我的 web.config 文件

XML
<system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="TransportSecurity">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service  behaviorConfiguration="TestWcfHttps1.Service1" name="TestWcfHttps1.Service1">
        <endpoint address="https://MYSERVER/GpTest/Service1.svc" 
                  binding="basicHttpBinding" 
                  bindingConfiguration="TransportSecurity"
                  contract="TestWcfHttps1.IService1">
          <identity>
            <dns value="" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="TestWcfHttps1.Service1">
          <serviceMetadata httpsGetEnabled="true" externalMetadataLocation="https://MYSERVER//GpTest/Service1.wsdl" />
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

コメント

タイトルとURLをコピーしました