Lỗi: Không có điểm cuối lắng nghe tại…

lập trình


WCF và HTTPS, Lỗi: Không có điểm cuối lắng nghe, Điều này thường xảy ra do địa chỉ hoặc hành động SOAP không chính xác

Tôi đang cố định cấu hình Dịch vụ WCF để hoạt động qua HTTPS và tôi đang gặp nhiều vấn đề.

Tôi đang triển khai https trên máy chủ dev của mình bằng chứng chỉ tự ký, mọi thứ đều hoạt động tốt. Khi tôi chuyển sang sản xuất, tất cả các giá trị cho các url đều được đọc bằng tên máy chủ thay vì địa chỉ trang web của tôi.

Tôi đã thêm tiêu đề máy chủ vào HTTPS trên máy chủ web của mình, điều này sẽ cho phép tôi tránh sử dụng wsdl và xsd tĩnh nhưng không được. Không có giá trị tĩnh, tất cả các url đều mặc định tên máy chủ.

Vì vậy, tôi đã định cấu hình dịch vụ để có các tệp wsdl và xsd tĩnh, tất cả đều chứa https trong địa chỉ của chúng. Sau đó tôi đã sao chép những tập tin này vào thư mục trang web của mình để chúng được lưu trữ. Những tệp đó được lưu trữ trong trang web của tôi và địa chỉ đang được sử dụng đều được phân giải chính xác.

Trong wsdl cho địa chỉ soad của tôi, tôi có giá trị bằng https. Giá trị https đang gây ra lỗi. Khi tôi thay thế https bằng http thì dịch vụ sẽ hoạt động nhưng khi

Tôi kiểm tra bằng wire shark dữ liệu không được mã hóa. Không tốt.
Làm thế nào tôi có thể làm việc này?

Tôi có một dự án thử nghiệm mà tôi có thể gửi để thử nghiệm.
Đây là lỗi tôi nhận được:

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)

Giải pháp 1

Tôi đã làm được, cần sự kết hợp của ba giải pháp khác nhau

1. Kích hoạt tiêu đề máy chủ HTTPS
2. Kích hoạt tệp wsdl và xsd tĩnh
3. Cấu hình web.config

Vì vậy, để kích hoạt HTTPS cho WCF tôi phải

1. Tạo các tệp wsdl và xsd tĩnh

Được, làm thế nào?
1.1 theo liên kết ?wsdl và lưu dưới dạng loại tệp .wsdl. Sửa đổi tệp và thay đổi địa chỉ soad thành https. Bạn sẽ liên kết đến tệp này từ máy chủ nhà phát triển của mình vì máy chủ trực tiếp của bạn rất có thể sẽ có liên kết đến tên máy chủ chứ không phải url bạn thực sự muốn sử dụng
Tệp 1.2 in .wsdl tạo tệp .xsd cho mỗi liên kết xsd trong wsdl (ví dụ: xsd0.xsd, xsd1.xsd, xsd2.xsd)
1.3 cập nhật tất cả các tham chiếu đến tài liệu xsd trong tệp wsdl và xsd để sử dụng các tệp xsd mới mà bạn đã tạo. Trỏ tới các giá trị được lưu trữ bằng url bạn muốn sử dụng, tất cả địa chỉ hiện sẽ sử dụng https
1.3 Lưu trữ tất cả các tệp đó trong thư mục gốc của ứng dụng web của bạn và kiểm tra xem mỗi url có phân giải chính xác không
1.4 Lưu ý: mỗi khi bạn thực hiện thay đổi đối với dịch vụ, bạn sẽ cần phải xây dựng lại tất cả các tệp tĩnh theo cách này

2. Kích hoạt tiêu đề máy chủ HTTPS trên máy chủ IIS trực tiếp (không có gui cho việc này, phải sử dụng dòng lệnh)

3. Sửa đổi cấu hình web Dịch vụ để bao gồm chế độ Bảo mật Truyền tải và HTTPS trong các thuộc tính sau (tìm “https” trong web.config bên dưới)

Đây là tập tin web.config của tôi

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をコピーしました