2010-07-01 22 views
0

我的客戶端需要將Url傳遞給我的WSDL Web服務。他們使用SoapHttpClientProtocol Url屬性來設置它的值。例如我的客戶通過URL值,這是「http://www.contoso.com/math.asmx」:如何從Web服務使用者訪問url屬性

namespace MyMath { 
    using System.Diagnostics; 
    using System.Xml.Serialization; 
    using System; 
    using System.Web.Services.Protocols; 
    using System.Web.Services; 


    [System.Web.Services.WebServiceBindingAttribute(Name="MyMathSoap", Namespace="http://www.contoso.com/")] 
    public class MyMath : System.Web.Services.Protocols.SoapHttpClientProtocol { 

     [System.Diagnostics.DebuggerStepThroughAttribute()] 
     public MyMath() { 
      this.Url = "http://www.contoso.com/math.asmx"; 
     } 

     [System.Diagnostics.DebuggerStepThroughAttribute()] 
     [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.contoso.com/Add", RequestNamespace="http://www.contoso.com/", ResponseNamespace="http://www.contoso.com/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] 
     public int Add(int num1, int num2) { 
      object[] results = this.Invoke("Add", new object[] {num1, 
         num2}); 
      return ((int)(results[0])); 
     } 

     [System.Diagnostics.DebuggerStepThroughAttribute()] 
     public System.IAsyncResult BeginAdd(int num1, int num2, System.AsyncCallback callback, object asyncState) { 
      return this.BeginInvoke("Add", new object[] {num1, 
         num2}, callback, asyncState); 
     } 

     [System.Diagnostics.DebuggerStepThroughAttribute()] 
     public int EndAdd(System.IAsyncResult asyncResult) { 
      object[] results = this.EndInvoke(asyncResult); 
      return ((int)(results[0])); 
     } 
    } 
} 

不過,我需要檢查是通行證soapClient.Url我的Web方法中的價值。 Web服務例子:

<%@ WebService Language="C#" Class="MyMath"%> 
using System.Web.Services; 
using System; 

[WebService(Namespace="http://www.contoso.com/")] 
public class MyMath { 
     [ WebMethod ] 
     public int Add(int num1, int num2) { 
      //need to place logic to check the url pass by clients. 
      //if (url) place a logic here 
      //how do i check the SoapHttpClientProtocol url property? 

      return num1+num2; 
      } 
} 

我如何可以訪問我的客戶在我的web服務方法設置這些SoapHttpClientProtocol Url屬性值?

任何人請諮詢。

+0

這是什麼樣的網絡服務? ASMX? WCF? – 2010-07-03 00:39:31

+0

Web服務是ASMX。 – jeff 2010-07-03 04:38:37

回答

0

SoapHttpClientProtocol對象的屬性用於創建從客戶端到您的服務的連接。這些屬性包括URL,網絡憑證和其他連接相關信息。

這些都不會發送到服務。它只使用使用

現在,我不知道你爲什麼需要這些信息。如果你真的需要它,那麼你應該把它發送到一個SOAP Header中,並將它作爲服務契約的一部分。

或者,您可以使用WCF。它實現WS-Addressing,它在SOAP Envelope中傳遞這些信息。

+0

我可能會改變我的邏輯方法。感謝你的回答。 – jeff 2010-07-04 10:23:45