I have two asp.net websites(say abc and pqr). First application 'abc' has the webservice ListingData.asmx and second application pqr has a web page that consumes that webservice. 'abc' application runs on https and 'pqr' runs on http. The code for asmx on 'abc site' is:
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
}
To consume this webservice the c# code is :
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);
I have added the webservice reference through 'Add Service Reference'
The stack trace shows following error:
"{System.Net.WebException: The request failed with an empty response. at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)"
Both sites are hosted on windows server web with IIS 7.
I have been searching the internet from last two days to resolve this error but could not find a solution which can be applied in my situation.
Any advice/suggestions would be appreciated.