Link to home
Get AccessLog in
Avatar of plq
plqFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ASP.NET webservice - calling from .NET 4.0

I am trying to call a web service which is a non WCF service (its compiled in .NET4 but uses the older .NET2 protocols)

        Dim sURL As String = txtURL.Text

        c = New ServiceReference1.WebServiceSoapClient("WebServiceSoap", sURL.Trim.TrimEnd("/"c) & "/webservice.asmx")

This works but when I try to consume it it comes up with the errors:

The client certificate is not provided. Specify a client certificate in ClientCredentials.



          <security mode="Message">
            <transport clientCredentialType="Windows" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="Certificate"
              algorithmSuite="Default" />

          </security>

or with this in app.config

          <security mode="Message">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>

I get the error

BasicHttp binding requires that BasicHttpBinding.Security.Message.ClientCredentialType be equivalent to the BasicHttpMessageCredentialType.Certificate credential type for secure messages. Select Transport or TransportWithMessageCredential security for UserName credentials.

Basically what I want is to say in code "connect via windows auth" or "connect via anon auth" - I don't want to be changing app.config since the service could be either of these depending on the server its on - we have locally installed customers with windows auth and we have hosted customers with anon auth - so how can I get past this and have the code decide whether to connect with windows auto or anon auth ?

thanks
Avatar of plq
plq
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

ok I got it working with this in app.config

          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Ntlm" />
          </security>


but what I really want is to be able to specify that in the VB, not in app.config - any ideas please?

thanks
Avatar of Stephan
You can set on the webserviceclientproxy the type of binding uou like to use. I don't have the exact code because i am on a mobile device
Hi,

It explained here - http://msdn.microsoft.com/en-us/library/ms731884.aspx

Hope it helps u...
Avatar of plq

ASKER

thanks, but how do I connect "c" to "b"


        c = New ServiceReference1.WebServiceSoapClient("WebServiceSoap", URL.Trim.TrimEnd("/"c) & "/webservice.asmx")


        Dim b As ServiceModel.WSHttpBinding = New ServiceModel.WSHttpBinding(ServiceModel.SecurityMode.TransportWithMessageCredential)
        b.Security.Transport.ClientCredentialType = ServiceModel.HttpClientCredentialType.Windows

i.e. how does windows know to use "b" and not whatever is in app.config or wherever?
There should be an overload with the following parameters:
System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress
Hi,

Don't specify in app.config file!

If you specify it in code, then it doesn't require in app.config file, if you specify in both places, i'm not sure how actually it works!

Moreover, it's recommended to update it in app.config file, since it's easy to change in future instead of compiling the code!

Hope it helps u...
Avatar of plq

ASKER

ok I'm nearly there with this code:

        Dim b As ServiceModel.WSHttpBinding = New ServiceModel.WSHttpBinding(ServiceModel.SecurityMode.TransportWithMessageCredential)
        b.Security.Transport.ClientCredentialType = ServiceModel.HttpClientCredentialType.Windows
        b.Security.Transport.ProxyCredentialType = ServiceModel.HttpProxyCredentialType.None
        b.Security.Transport.Realm = ""

        b.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default
        b.Security.Message.ClientCredentialType = ServiceModel.MessageCredentialType.Windows

        Dim e As New System.ServiceModel.EndpointAddress(URL.Trim.TrimEnd("/"c) & "/webservice.asmx")

        c = New ServiceReference1.WebServiceSoapClient(b, e)


problem is it just won't work with any combination of parameters I've tried this far.

Errors like:

The provided URI scheme 'http' is invalid; expected 'https'.
Avatar of plq

ASKER

If I change to securitymode.message I get this error:

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'.

This is attempting NT authentication with a http web server (not https)
Avatar of plq

ASKER

still stuck on this :(
Could you provide the URL you try to connect? Or a similar one?
Avatar of plq

ASKER

http://localhost:1271

Its just the asp.net web server
Just to get things straight;
- You have a ASP.NET webservice that is only accessible through basic authentication or NTLM?
- You have an application (probably a web or windows forms app?) that tries to connect to it?
- Both are hosted on thesame machine
Avatar of plq

ASKER

Yes. Well I have two webservices - one hosted on the web which I can test with SSL, that would accept anon auth.

And the dev instance of the same service as above, running in VS 2010 on the same machine - thats the one I'm having this problem with

As you can see the problem is, when I specify the right parameters in app.config, it will work. But when I try to access the dev instance via code setting instead of app.config it refuses to work despite that fact that it seems I have replicated the same settings in code

thanks
I've seen you are using Ntlm as setting on the app.config, maybe you need to send it on the transport:

WSHttpBinding binding = new WSHttpBinding(SecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;

Open in new window

Avatar of plq

ASKER

thats pretty much what I had, and when I change it to exactly what you suggest, I get the same error:

The provided URI scheme 'http' is invalid; expected 'https'.
Parameter name: via
Hi,

I think you need to set the ClientCredentialType as well -

http://msdn.microsoft.com/en-us/library/ms729789.aspx

Hope it helps u...
Avatar of plq

ASKER

this
        Dim b As ServiceModel.WSHttpBinding = New ServiceModel.WSHttpBinding(ServiceModel.SecurityMode.Message)
        b.Security.Transport.ClientCredentialType = ServiceModel.HttpClientCredentialType.Ntlm
        b.Security.Transport.ProxyCredentialType = ServiceModel.HttpProxyCredentialType.None

gives
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'.

this

        Dim b As ServiceModel.WSHttpBinding = New ServiceModel.WSHttpBinding(ServiceModel.SecurityMode.Message)
        b.Security.Transport.ClientCredentialType = ServiceModel.HttpClientCredentialType.None
        b.Security.Transport.ProxyCredentialType = ServiceModel.HttpProxyCredentialType.None

gives

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'.

this

        Dim b As ServiceModel.WSHttpBinding = New ServiceModel.WSHttpBinding(ServiceModel.SecurityMode.Transport)
        b.Security.Transport.ClientCredentialType = ServiceModel.HttpClientCredentialType.None
        b.Security.Transport.ProxyCredentialType = ServiceModel.HttpProxyCredentialType.None

and this

        Dim b As ServiceModel.WSHttpBinding = New ServiceModel.WSHttpBinding(ServiceModel.SecurityMode.Transport)
        b.Security.Transport.ClientCredentialType = ServiceModel.HttpClientCredentialType.Ntlm
        b.Security.Transport.ProxyCredentialType = ServiceModel.HttpProxyCredentialType.None

all give


The provided URI scheme 'http' is invalid; expected 'https'.
Parameter name: via


thanks
Hi,

It's pretty weird that, it's working if the settings is specified in app.config file and not when you code the same!

Moreover did you set the SecuityMode, as you do in the app.config file -

    <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Ntlm" />
          </security>

Open in new window


Check the similar thread - http://stackoverflow.com/questions/1690784/provided-uri-schemehttp-is-invalid-expected-https

Hope it helps u...
Avatar of plq

ASKER

thanks for helping guys. I'm no further forward with it unfortunately.. I don't know what else we can do :(

This line does, I believe, set the client credential type as per your xml settings above..

    b.Security.Transport.ClientCredentialType = ServiceModel.HttpClientCredentialType.Ntlm
ASKER CERTIFIED SOLUTION
Avatar of Roopesh Reddy
Roopesh Reddy
Flag of India image

Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
Avatar of plq

ASKER

Never found an answer - gave up.. thanks for trying anyway
I regret it :(