如何从Web服务使用者访问url属性

时间:2010-07-01 11:46:11

标签: c# web-services asmx

我的客户端需要将Url传递给我的WSDL Web服务。他们使用SoapHttpClientProtocol Url属性来设置它的值。示例我的客户端传递url值“http://www.contoso.com/math.asmx”:

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

但是,我需要检查传递给web方法中soapClient.Url的值。 示例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;
          }
 }

如何在我的网络服务方法中访问我的客户设置的这些SoapHttpClientProtocol Url属性值?

任何人请建议。

1 个答案:

答案 0 :(得分:0)

使用SoapHttpClientProtocol对象的属性来创建从客户端到服务的连接。这些属性包括URL,网络凭据和其他与连接相关的信息。

这些都不会发送到服务。它只是使用

现在,我不知道为什么你需要这些信息。如果你确实需要它,那么你应该将它发送到SOAP Header中,并使其成为服务合同的一部分。

或者,您可以使用WCF。它实现了WS-Addressing,它在SOAP Envelope中传递了这些信息。

相关问题