2017-12-13 4 views
1

私は2つのasp.net Webサイト(abcとpqrと言う)を持っています。最初のアプリケーション 'abc'にはWebサービスのListData.asmxがあり、2番目のアプリケーションpqrにはそのWebサービスを使用するWebページがあります。 'abc'アプリケーションはhttps上で動作し、 'pqr'はhttp上で動作します。 'ABCサイト' に関するASMXのためのコードは次のとおりです。SOAPエラーまたはhttps関連のエラー

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

は私が

'サービス参照の追加' を介してWebサービスの参照を追加しました:

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 
    } 

は、C#のコードは、このWebサービスを消費するにはスタックトレースは、次のエラーを示します。

"{System.Net.WebException:空の応答で要求が失敗しました。 at System.Web.Services.Protocols。 SoapHttpClientProtocol.ReadResponse(SoapClientMessageメッセージ、にWebResponse応答、ストリームresponseStream、ブールasyncCall)System.Web.Services.Protocols.SoapHttpClientProtocol.Invokeで (文字列methodNameの、オブジェクト[]パラメータ)」

両方のサイトでは、Windows Server上でホストされていますこのエラーを解決するために最後の2日間インターネットを検索していましたが、私の状況で適用できる解決策が見つかりませんでした。

ご意見やご提案がありがとうございます。

答えて

0

バインド構成のように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> 
+0

私はあなたの提案を試みましたが、今私にエラーが表示されます - {System.Net.WebException:HTTPステータス403:要求が失敗しました。 at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessageメッセージ、WebResponse応答、StreamResponseStream、Boolean asyncCall) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName、Object [] parameters) – user1254053

+0

Areプロキシを使用していますか?また、appconfigファイルを共有しますか? – lucky

+0

私は設定ファイルに何も追加していません。 – user1254053