【问题标题】:Soap error or https related errorSoap 错误或 https 相关错误
【发布时间】:2017-12-13 10:26:57
【问题描述】:

我有两个 asp.net 网站(比如 abc 和 pqr)。第一个应用程序“abc”有 web 服务 ListingData.asmx,第二个应用程序 pqr 有一个使用该 web 服务的网页。 “abc”应用程序在 https 上运行,“pqr”在 http 上运行。 'abc site' 上 asmx 的代码是:

    public class ListingAuthHeader : SoapHeader
    {
        public string Username;
        public string Password;
    }

    public class ListingAuthHeaderValidation
    {
    /// <summary>
    /// Validates the credentials of the soap header.
    /// </summary>       

    public static bool Validate(ListingAuthHeader soapHeader)
    {
        if (soapHeader == null)
        {
            throw new NullReferenceException("No soap header was specified.");
        }

        if (soapHeader.Username == null)
        {
            throw new NullReferenceException("Username was not supplied for authentication in SoapHeader.");
        }

        if (soapHeader.Password == null)
        {
            throw new NullReferenceException("Password was not supplied for authentication in SoapHeader.");
        }

        if (soapHeader.Username != "a" || soapHeader.Password != "b")
        {
            throw new Exception("Please pass the proper username and password for this service.");
        }

        return true;
        }
    }

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    public class ListingData  : System.Web.Services.WebService {


    public ListingAuthHeader CustomSoapHeader;

    [WebMethod]
    [SoapHeader("CustomSoapHeader")]

    public DataSet GetListingData(string countryId, int maxListings)
    {
    ListingAuthHeaderValidation.Validate(CustomSoapHeader);
    // then get data from database
    } 

要使用这个 web 服务,c# 代码是:

    ws.ListingData o = new ws.ListingData();
    ws.ListingAuthHeader h = new ws.ListingAuthHeader();
    h.Username = soapHeaderUsername;
    h.Password = soapHeaderPassword;
    o.ListingAuthHeaderValue = h;
    ds = o.GetListingData(countryId, maxListings);

我已经通过“添加服务参考”添加了网络服务参考

堆栈跟踪显示以下错误:

"{System.Net.WebException:请求失败,响应为空。 在 System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage 消息,WebResponse 响应,流 responseStream,布尔 asyncCall) 在 System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] 参数)"

这两个网站都托管在带有 IIS 7 的 Windows Server Web 上。

过去两天我一直在互联网上搜索以解决此错误,但找不到适用于我的情况的解决方案。

任何意见/建议将不胜感激。

【问题讨论】:

    标签: c# web-services soap


    【解决方案1】:

    您应该将客户端配置为通过 HTTPS 端点进行通信,如绑定配置。因此,将设置放入应用程序配置并配置服务名称;

      <system.serviceModel>
        <bindings>
         <basicHttpBinding>
              <binding name="HttpsBindindConfiguration">
                <security mode="Transport" />        
              </binding>
        </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="https://abc/ListData.asmx" binding="basicHttpBinding" bindingConfiguration="HttpsBindindConfiguration" contract="ListDataClient" name="ListDataClient" />
        </client>
      </system.serviceModel>
    

    【讨论】:

    • 我尝试了你的建议,但现在它给了我错误 - {System.Net.WebException: The request failed with HTTP status 403: Forbidden.在 System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage 消息,WebResponse 响应,流 responseStream,布尔 asyncCall)在 System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(字符串方法名,对象 [] 参数)
    • 你在使用代理吗?另外,你会分享 appconfig 文件吗?
    • 我没有在任何配置文件中添加任何东西。
    • 我不确定代理。我只是在 Windows Server Web Firefox 浏览器上运行我的应用程序
    • 你可以从浏览器访问网络服务吗?
    猜你喜欢
    • 2018-04-19
    • 2013-03-10
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 2019-04-04
    • 1970-01-01
    相关资源
    最近更新 更多