肥皂错误或与https相关的错误

时间:2017-12-13 10:26:58

标签: c# web-services soap

我有两个asp.net网站(比如abc和pqr)。第一个应用程序'abc'具有webservice ListingData.asmx,第二个应用程序pqr具有使用该webservice的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服务器Web上。

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

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

1 个答案:

答案 0 :(得分:0)

您应该将客户端配置为通过HTTPS端点进行通信,例如绑定配置。因此,将设置放在应用程序配置中并配置servicename;

  <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>