Authorization - WSDL File, Proxy class in C#

Markus Freitag 3,786 Reputation points
2022-01-17T10:01:04.123+00:00

Hello,

I have received a WSDL file from a customer. With this I have created a proxy class via WSDL. --> IO
The server must be connected via Authorization.
I don't see anything there. How can I make the connection via Authorization?
The proxy class is quite complex. I need only 2 requests.

Is there any way I can best create the request. There is no support from the customer.

The alternative would be to create it myself via XDocument, which I am not in favor of.

 private void btnOrderData_Click(object sender, EventArgs e)
        {
            using (PDXCSMEService danS = new PDXCSMEService())
            {
                //danS .Url = "";

//  danS.Auto....???
Internet Information Services
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,288 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,205 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,309 questions
0 comments No comments
{count} votes

Accepted answer
  1. AgaveJoe 26,146 Reputation points
    2022-01-20T14:44:58.337+00:00

    Not work, no Url inside the proxy class. Is my call wrong?

    I'm guessing you did not thoroughly read the svcutil.exe reference documentation which clearly indicates the svcutil.exe creates a output.config file. The config file contains the URL as well as other configurations. Either rename output.config to app.config and place the file in the application root or copy the appropriate nodes to you app.config file.

    Keep in mind, I'm just guessing what's wrong as I do not have the wsdl, service documentation, and you've provide very little code. Still the service owners are your best option. Otherwise, maybe hire someone that can help you.

    Example configuration that uses HTTP. Change to Transport security for HTTPS.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="WebServiceSoap">
         <security mode="TransportCredentialOnly">
         <transport clientCredentialType="Basic" />
         </security>
         </binding>
                </basicHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost/WebService/WebService.asmx"
                    binding="basicHttpBinding" bindingConfiguration="WebServiceSoap"
                    contract="WebServiceSoap" name="WebServiceSoap" />
            </client>
        </system.serviceModel>
    </configuration>
    

    Implementation

    static void Main(string[] args)
    {
        WebServiceSoapClient client = new WebServiceSoapClient("WebServiceSoap");
    
        client.ClientCredentials.UserName.UserName = "username";
        client.ClientCredentials.UserName.Password = "password!";
    
        string resposne = client.HelloWorld();
        Console.WriteLine(resposne);
    }
    
    1 person found this answer helpful.

5 additional answers

Sort by: Most helpful
  1. Ken Tucker 5,846 Reputation points
    2022-01-17T10:17:58.99+00:00

    If you use wsdl.exe to generate the proxy class the class has a credentials property you can set to a network credentials

    https://learn.microsoft.com/en-us/archive/msdn-magazine/2002/december/the-xml-files-wsdl-web-services-and-more

    1 person found this answer helpful.

  2. AgaveJoe 26,146 Reputation points
    2022-01-17T13:11:04.377+00:00

    There are several ways to secure a SOAP service. The members of this forum have no idea how the SOAP security works. You have no choice but to contact the service owners for support.

    1 person found this answer helpful.

  3. AgaveJoe 26,146 Reputation points
    2022-01-18T18:27:06.35+00:00

    You still have not told us how the security works! If the service uses basic authentication and you have credentials then the pattern below will work.

    static void Main(string[] args)
    {
        RemoteService.WebService client = new RemoteService.WebService()
        {
            Credentials = new NetworkCredential("username", "password"),
            PreAuthenticate = true,
            Url = "http://localhost/WebService/WebService.asmx"
        };
    
        string resposne = client.HelloWorld();
        Console.WriteLine(resposne);
    }
    
    1 person found this answer helpful.

  4. AgaveJoe 26,146 Reputation points
    2022-01-19T16:21:01.047+00:00

    The client, which I assume is SoapUI, expects an XML response (SOAP) but instead received an HTML response. Commonly, the HTML response it is an error message from the server. Open the HTML in a browser and/or read the contents of the message.

    1 person found this answer helpful.