question

MarkusFreitag-0088 avatar image
0 Votes"
MarkusFreitag-0088 asked MarkusFreitag-0088 commented

Authorization - WSDL File, Proxy class in C#

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....???


dotnet-csharpwindows-serverwindows-server-iisdotnet-aspnet-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AgaveJoe avatar image
1 Vote"
AgaveJoe answered MarkusFreitag-0088 commented

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for your help!

0 Votes 0 ·
vb2ae avatar image
1 Vote"
vb2ae answered MarkusFreitag-0088 commented

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

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

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Can you make a sample, how I should call wsdl.exe.

 wsdl AuthenNEW.wsdl /pu:freitag /pp:20221234 /pd:2022AAA

Is not working, I found nothing inside the proxy class. Any idea?


0 Votes 0 ·

Do I need the Headers? I think so.
Creating the proxy class via WSDL does not create this.
How can I check, how can I create it correctly?
What options do I have. I assume it's because of that.

                      string credentials1 = String.Format("{0}:{1}", "usernameTEST", "userPassTest");
                      byte[] bytes = Encoding.ASCII.GetBytes(credentials1);
                      string base64 = Convert.ToBase64String(bytes);
                      string authorization = String.Concat("Basic ", base64);
                     // dMES.Headers.Add("Authorization", authorization);
0 Votes 0 ·
AgaveJoe avatar image
1 Vote"
AgaveJoe answered AgaveJoe converted comment to answer

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.

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

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.

ok, but maybe there is a way to set it inside my code. Creditional?

0 Votes 0 ·
AgaveJoe avatar image AgaveJoe MarkusFreitag-0088 ·

ok, but maybe there is a way to set it inside my code. Creditional?

Set what? How does the security work?

1 Vote 1 ·
     WebRequest request = WebRequest.Create(url);
         request.Method = WebRequestMethods.Http.Get;
         NetworkCredential networkCredential = new NetworkCredential(logon, password); // logon in format "domain\username"
         CredentialCache myCredentialCache = new CredentialCache {
                      {new Uri(url), "Basic", networkCredential}};
         request.PreAuthenticate = true;
         request.Credentials = myCredentialCache;

Like this.
I have a WSDL file, call WSDL.EXE to create a proxy class --> IO
Now customer told me, he need a autorisation. I never made it, now idea.
Is it possible via wrapper class or it is a todo, when I create the proxy class?
How I can set, user, password and the authorisation id.




0 Votes 0 ·
Show more comments
AgaveJoe avatar image
1 Vote"
AgaveJoe answered MarkusFreitag-0088 edited

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @AgaveJoe,

Thanks!

 private void btnGet_Order_Queue_Click(object sender, EventArgs e)
 {
     using (PDC_WS_LMEService dMES = new PDC_WS_LMEService()
     {
         Credentials = new NetworkCredential("userXXX", "passWordXXXX"),
         PreAuthenticate = true,
         Url = "http://AXXXA724:8080/orawsv/PDS/PSLME"
     }) 
     {
         try
         {
             ORD_REQType requestInput = new ORD_REQType();
             requestInput.ORD_REQ = new ORD_REQTypeLREQ();

I think it is better, i got another error.

   The request content type found by the client is 'text/html; charset=iso-8859-1', was expected 'text/xml'.
     Error message
     --
     <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">


What can be the cause, how can I change this?
From customer! With SoapUI
Is Basic

166491-basic004.png



Can it be the WSDL file? Is wrong, false type. Can I create this myself? Maybe with SoapUi




0 Votes 0 ·
basic004.png (31.4 KiB)
AgaveJoe avatar image
1 Vote"
AgaveJoe answered AgaveJoe converted comment to answer

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.

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


I found this.


 dMES.RequestEncoding =


Can I set it to

      request.Accept = "text/xml";
      request.ContentType = "text/xml";
      request.Headers.Add("Content-Encoding", "utf-8");


I found nothing.

166474-basic0034.png


0 Votes 0 ·
basic0034.png (23.2 KiB)
AgaveJoe avatar image AgaveJoe MarkusFreitag-0088 ·

My best guess is the SOAP service expects SOAP version 1.2 Try using svcutil.exe rather than wsdl.exe to create the proxy.

Again, the service owners know how their service works. Either read the the support docs or contact the service owners. You also might consider taking classes on SOAP or setting aside time to learn the protocol.


1 Vote 1 ·

OK, but it a way to set this request.ContentType = "text/xml";

Problem: No support from service owner. Reason: No experience with C#

0 Votes 0 ·
Show more comments

Hello,

use now


 svcutil AuthenNEW.wsdl /language:C#

system-servicemodel-missing



Some DLLs missing, I added it.
Not work, no Url inside the proxy class. Is my call wrong?

0 Votes 0 ·
LimitlessTechnology-2700 avatar image
1 Vote"
LimitlessTechnology-2700 answered MarkusFreitag-0088 commented

Hi there,

Basic authentication is supported by specifying a policy in the WSDL. A basic authentication policy can be added to the WSDL either manually or by using the WS-Policy Attachment window accessed from CASA and provided through Tango (WSIT). A basic authentication policy is specified at the root level of the WSDL and a reference to the policy is made in the WSDL Port type section, binding the policy to the endpoint.



--If the reply is helpful, please Upvote and Accept it as an answer--

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the answer.

A basic authentication policy can be added to the WSDL either manually or by using the WS-Policy Attachment window accessed from CASA and provided through Tango (WSIT).

Yes, Can you make a sample for manually? Or both?

0 Votes 0 ·