2010-07-01 25 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