【发布时间】: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