如何解决SOAP服务调用时‘无监听端点可接收消息’的问题?
解决“没有可接收消息的监听端点”SOAP服务调用问题
咱们一起来排查这个问题,这种错误通常和端点地址、SOAP Action不匹配,或者绑定配置与服务端不一致有关。结合你提供的ASP.NET配置文件,我整理了几个关键排查方向:
1. 确认端点调用地址的正确性
你提供的WSDL地址是https://190.0.195.24:9001/paymentgw/services/paymentgw?wsdl,但配置文件里的endpoint地址是不带?wsdl的https://190.0.195.24:9001/paymentgw/services/paymentgw——这本身是合理的(WSDL地址是服务描述文件,实际调用地址不需要后缀),但还是要验证:
- 用浏览器直接访问配置里的endpoint地址,看是否能返回服务相关的响应(比如“Endpoint not found”或者服务描述内容);
- 用SOAPUI工具导入这个WSDL,看工具自动生成的调用端点地址是什么,和你配置的地址对比,是否存在路径差异(比如有些服务会用
.soap后缀,或者路径末尾有额外标识)。
2. 检查SOAP Action是否匹配
很多时候这个错误是因为客户端发送的SOAP Action不符合服务端的预期。你可以尝试以下操作:
- 查看自动生成的代理类(
VisaNetWSTest.PaymentGW)里的方法标记,确认[OperationContract]的Action属性是否和服务端要求一致; - 如果不确定,可以在配置里显式添加端点行为,同时处理HTTPS证书可能的问题(仅测试环境临时使用,生产环境需配置信任证书):
<system.serviceModel> <!-- 新增端点行为配置 --> <behaviors> <endpointBehaviors> <behavior name="PaymentGWEndpointBehavior"> <clientCredentials> <serviceCertificate> <authentication certificateValidationMode="None" /> </serviceCertificate> </clientCredentials> </behavior> </endpointBehaviors> </behaviors> <client> <!-- 在endpoint中关联上述行为 --> <endpoint address="https://190.0.195.24:9001/paymentgw/services/paymentgw" binding="basicHttpBinding" bindingConfiguration="PaymentGW_SOAPBinding" contract="VisaNetWSTest.PaymentGW" name="PaymentGWServicesPort" behaviorConfiguration="PaymentGWEndpointBehavior"/> </client> <!-- 其他配置保持不变 --> </system.serviceModel>
3. 验证绑定配置与服务端匹配
你的配置里用了basicHttpBinding且安全模式为Transport(适配HTTPS),但要确认服务端的绑定配置是否和客户端一致:
- 服务端是否也是使用
basicHttpBinding?有没有启用消息安全或者其他验证方式? - 可以尝试显式指定绑定的消息编码,避免意外的格式不兼容:
<basicHttpBinding> <binding name="PaymentGW_SOAPBinding" messageEncoding="Text"> <security mode="Transport"/> </binding> </basicHttpBinding>
4. 查看InnerException获取更细节的错误
你提到如果存在InnerException要查看,建议在代码里捕获完整的异常信息,这能帮你定位更具体的问题:
try { using (var serviceClient = new VisaNetWSTest.PaymentGWClient()) { // 替换成你实际调用的服务方法 serviceClient.YourPaymentMethod(); } } catch (Exception ex) { // 输出完整异常信息到调试窗口或日志 var fullError = ex.ToString(); System.Diagnostics.Debug.WriteLine(fullError); }
原始配置文件参考
<?xml version="1.0" encoding="utf-8"?> <!-- For more information on how to configure your ASP.NET application, please visit https://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <connectionStrings> <add name="cadenaserver" connectionString="Data Source=SQL7001.site4now.net;Initial Catalog=DB_A2CE26_PaymentDB;User Id=DB_A2CE26_PaymentDB_admin;Password=;" providerName="System.Data.SqlClient" /> <add name="cadenaserverb" connectionString="Data Source=SQL7001.site4now.net;Initial Catalog=DB_A2CE26_PaymentDB;User Id=DB_A2CE26_PaymentDBBackUp_admin;Password=;" providerName="System.Data.SqlClient" /> <add name="cadenalocal" connectionString="Data Source=DAVID-HP\SQLEXPRESS01;Initial Catalog=DB_A2CE26_PaymentDB;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings> <system.web> <customErrors mode="Off" /> <compilation debug="true" targetFramework="4.6.1"> <assemblies> <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> </assemblies> </compilation> <httpRuntime targetFramework="4.6.1" /> </system.web> <appSettings> <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" /> </appSettings> <system.serviceModel> <client> <endpoint address="https://190.0.195.24:9001/paymentgw/services/paymentgw" binding="basicHttpBinding" bindingConfiguration="PaymentGW_SOAPBinding" contract="VisaNetWSTest.PaymentGW" name="PaymentGWServicesPort" /> </client> <bindings> <basicHttpBinding> <binding name="PaymentGW_SOAPBinding"> <security mode="Transport"/> </binding> <binding name="PaymentGW_SOAPBinding1" /> </basicHttpBinding> </bindings> </system.serviceModel> <system.webServer> <handlers> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <remove name="OPTIONSVerbHandler" /> <remove name="TRACEVerbHandler" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers> </system.webServer> </configuration>
内容的提问来源于stack exchange,提问作者David Alejandro Ramos Escobar
相关产品推荐
相关产品推荐

