HTTP Authentication for web services

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Markus Brandy

    #1

    HTTP Authentication for web services

    Hi,

    I have to use a Java web service that requires HTTP authentication, so
    I have to send username and password in the HTTP headers.

    My C# application has a client implementation that looks like this:

    [System.Diagnost ics.DebuggerSte pThroughAttribu te()]
    [System.Componen tModel.Designer CategoryAttribu te("code")]
    [System.Web.Serv ices.WebService BindingAttribut e(Name="MyServi ceSoapBinding",
    Namespace="http ://localhost:8080/services/MyService")]
    public class MyService :
    System.Web.Serv ices.Protocols. SoapHttpClientP rotocol {

    public MyService() {
    this.Url = "http://localhost:8080/services/MyService";
    }

    [System.Web.Serv ices.Protocols. SoapRpcMethodAt tribute("",
    RequestNamespac e="http://webservices.my" ,
    ResponseNamespa ce="http://localhost:8080/services/MyService")]
    public void addUserData(Use rData in0) {
    this.Invoke("ad dUserData", new object[] {
    in0});
    }

    public System.IAsyncRe sult BeginaddUserDat a(UserData in0,
    System.AsyncCal lback callback, object asyncState) {
    return this.BeginInvok e("addUserData" , new object[] {
    in0}, callback, asyncState);
    }

    public void EndaddUserData( System.IAsyncRe sult asyncResult) {
    this.EndInvoke( asyncResult);
    }
    };

    The client uses the service like this:

    MyService myService = new MyService();
    myService.addUs erData(userData );

    It works fine, if no authentication is required. How can I implement
    the HTTP authentication?

    Thanks,
    Markus Brandy
  • feroze [msft]

    #2
    Re: HTTP Authentication for web services

    There are two ways that I can think of:

    1) if the proxy supports setting credentials, set the credentials using
    that.
    2) You can override the GetWebRequest() method of gthe proxy. Then, on the
    WebRequest object that you get, you can set NetworkCredenti als.

    feroze
    =============

    "Markus Brandy" <da_joker@gmx.n et> wrote in message
    news:b75bcd72.0 406280510.5b8ad 90b@posting.goo gle.com...[color=blue]
    > Hi,
    >
    > I have to use a Java web service that requires HTTP authentication, so
    > I have to send username and password in the HTTP headers.
    >
    > My C# application has a client implementation that looks like this:
    >
    > [System.Diagnost ics.DebuggerSte pThroughAttribu te()]
    > [System.Componen tModel.Designer CategoryAttribu te("code")]
    >[/color]
    [System.Web.Serv ices.WebService BindingAttribut e(Name="MyServi ceSoapBinding",[color=blue]
    > Namespace="http ://localhost:8080/services/MyService")]
    > public class MyService :
    > System.Web.Serv ices.Protocols. SoapHttpClientP rotocol {
    >
    > public MyService() {
    > this.Url = "http://localhost:8080/services/MyService";
    > }
    >
    > [System.Web.Serv ices.Protocols. SoapRpcMethodAt tribute("",
    > RequestNamespac e="http://webservices.my" ,
    > ResponseNamespa ce="http://localhost:8080/services/MyService")]
    > public void addUserData(Use rData in0) {
    > this.Invoke("ad dUserData", new object[] {
    > in0});
    > }
    >
    > public System.IAsyncRe sult BeginaddUserDat a(UserData in0,
    > System.AsyncCal lback callback, object asyncState) {
    > return this.BeginInvok e("addUserData" , new object[] {
    > in0}, callback, asyncState);
    > }
    >
    > public void EndaddUserData( System.IAsyncRe sult asyncResult) {
    > this.EndInvoke( asyncResult);
    > }
    > };
    >
    > The client uses the service like this:
    >
    > MyService myService = new MyService();
    > myService.addUs erData(userData );
    >
    > It works fine, if no authentication is required. How can I implement
    > the HTTP authentication?
    >
    > Thanks,
    > Markus Brandy[/color]


    Comment

    Working...