none
C# http://localhost:9080/XXXX.asmx / WSDL / Timeout RRS feed

  • Question

  • Hello,
    I have created a DLL which allows the connection to a webserver with servicereference in C# project.
    My goal is.
       To change the endpoint configuration by xml(config) file. How I can do it?
       Do I have to copy the configuration entries manually into the configuration file of the exe?
       Can I define the timeout via C# code?
      Timeout for establishing a connection?
      Timeout for the answer?
      Change the address from local host to another address?
       How to do it correctly, how can I implement it?
      
      I found this. I can't get any further.   

      
       What is the difference between asmx and wsdl , when do I need what?
    Many thanks for tips, examples, solutions and hints in advance.

    Greetings Markus

    <!-- ########################################## -->
    
    App.config   DLL
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="orderInfoSoap" />
                    <binding name="productSoap" />
                    <binding name="readySoap" />
                </basicHttpBinding>
              </bindings>
            <client>
                <endpoint address="http://localhost:8081/orderInfo.asmx" binding="basicHttpBinding"
                    bindingConfiguration="orderInfoSoap" contract="ServiceReferenceOrderInfo.orderInfoSoap"
                    name="orderInfoSoap" />
    				
    App.config    EXE				
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
      </startup>
    </configuration>
    
    
    Is creating a wrapper class automaitically.
    [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
        public partial class orderInfoSoapClient : System.ServiceModel.ClientBase<Conv.ServiceReferenceOrderInfo.orderInfoSoap>, Conv.ServiceReferenceOrderInfo.orderInfoSoap {
            
            public orderInfoSoapClient() {
            }
            
            public orderInfoSoapClient(string endpointConfigurationName) : 
                    base(endpointConfigurationName) {
            }
            
            public orderInfoSoapClient(string endpointConfigurationName, string remoteAddress) : 
                    base(endpointConfigurationName, remoteAddress) {
            }
            
            public orderInfoSoapClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
                    base(endpointConfigurationName, remoteAddress) {
            }
            
            public orderInfoSoapClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                    base(binding, remoteAddress) {
            }


    Tuesday, December 3, 2019 6:09 PM

Answers

All replies

  • Hi,

    Yes, we have to copy the generated configuration from the current class library project to the configuration file in your main project that is recognized in the hosting environment. This is due to the fact that the class library project doesn’t own a configuration file. When we generate a proxy client instance to access the server in the main project, the configuration file of the main project must contain the System.servicemodel section and the corresponding service configuration. this is a bit similar to when we deployed the WCF class library project.
    https://docs.microsoft.com/en-us/dotnet/framework/wcf/deploying-a-wcf-library-project
    For compatibility with the XML web service(ASMX), WCF created by basichttpbinding is equivalent to the xml web service. Therefore, we could call the service by using ChannelFactory created by Basichttpbinding.

                ServicePointManager.ServerCertificateValidationCallback += delegate
                {
                    return true;
                };
                ServiceReference1.WebService1SoapClient client = new ServiceReference1.WebService1SoapClient();
                BasicHttpBinding binding = new BasicHttpBinding();
                binding.Security.Mode = BasicHttpSecurityMode.Transport;
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                Uri uri = new Uri("https://10.157.13.69:44323/WebService1.asmx");
                ChannelFactory<WebService1Soap> factory = new ChannelFactory<WebService1Soap>(binding, new EndpointAddress(uri));
                WebService1Soap service = factory.CreateChannel();
                var result = service.HelloWorld(new HelloWorldRequest());
                Console.WriteLine(result.Body.HelloWorldResult);
    

    For more details about the ChannelFactory.
    https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-use-the-channelfactory
    https://docs.microsoft.com/en-us/dotnet/framework/wcf/samples/channel-factory
    As long as we start to programming the binding type, we are capable of set up the timeout

    BasicHttpBinding binding = new BasicHttpBinding();
                binding.SendTimeout = new TimeSpan(0, 10, 0);
                binding.CloseTimeout = new TimeSpan(0, 10, 0);
                binding.OpenTimeout = new TimeSpan(0, 10, 0);
                binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
    


    We can also change it in the generated configuration file.

    <bindings>
          <basicHttpBinding>
            <binding name="WebService1Soap" sendTimeout="00:10:00" closeTimeout="00:10:00">
              <security mode="Transport" />
            </binding>
    

    Feel free to let me know if there is anything I can help with.

    Best Regards

    Abraham


    Wednesday, December 4, 2019 9:20 AM
    Moderator
  • Dear Abraham,
    Thanks for the response. Is not so easy.
    First:
       It is possible to configure the complete code without any entries in the EXE APP.Config?
       If yes, how?
    Second:
    Can you please publish the whole example for me?
    What does the DLL App.Config have to look like?
    What does the EXE App.Config have to look like?
    ////  EXE
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <runtime>
        <gcServer enabled="true"/>
        <loadFromRemoteSources enabled="true" />
        <AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
      </runtime>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
      </startup>
    </configuration>
    
    //// DLL ######
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="orderInfoSoap" />
                    <binding name="productSoap" />
                    <binding name="readySoap" />
                </basicHttpBinding>
              </bindings>
            <client>
                <endpoint address="http://localhost:4080/orderInfo.asmx" binding="basicHttpBinding"
                    bindingConfiguration="orderInfoSoap" contract="ServiceReferenceOrderInfo.orderInfoSoap"
                    name="orderInfoSoap" />
                ….
            </client>
        </system.serviceModel>
    </configuration>
    Thanks in advance.
    Greetings Markus


    Thursday, December 5, 2019 6:02 PM
  • Please avoid the issue to be a verbose discussion, simplify this thread to make it involve a single center point.
    If there are many questions you encountered when you handle WCF (not XML web service), please post a new thread, so that help whoever runs into a similar issue.
    Back to your question.
    It is possible to configure the complete code without any entries in the EXE APP.Config?
       If yes, how?
    As I mentioned above, we could call the service by using ChannelFactory, it doesn’t require extra configuration in the APPConfig, this is because we have to configure the relevant configuration in code, the binding, service endpoint and so on.
    Complete code.
    WebService1.asmx1(located in 10.157.13.69)
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        [System.Web.Script.Services.ScriptService]
        public class WebService1 : System.Web.Services.WebService
        {
    
            [WebMethod]
            public string HelloWorld()
            {
                return "Hello World";
            }
    }
    

    Client-side.
    //trust the server certificate.            
    ServicePointManager.ServerCertificateValidationCallback += delegate
                {
                    return true;
                };
            
                BasicHttpBinding binding = new BasicHttpBinding();
                binding.Security.Mode = BasicHttpSecurityMode.Transport;
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                Uri uri = new Uri("https://10.157.13.69:44323/WebService1.asmx");
                ChannelFactory<WebService1Soap> factory = new ChannelFactory<WebService1Soap>(binding, new EndpointAddress(uri));
                WebService1Soap service = factory.CreateChannel();
                var result = service.HelloWorld(new HelloWorldRequest());
                Console.WriteLine(result.Body.HelloWorldResult);
    
    What is included in the configuration file, just like your configuration file, is mainly the system.servicemodel section.
    Best Regards
    Abraham


     
    Friday, December 6, 2019 6:47 AM
    Moderator
  • What is included in the configuration file, just like your configuration file, is mainly the system.servicemodel section.

     

    App.Config

    Is that right?

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <runtime>
        <gcServer enabled="true"/>
        <loadFromRemoteSources enabled="true" />
        <AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
      </runtime>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
      </startup
      
      <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="orderInfoSoap" />
                    <binding name="productSoap" />
                    <binding name="readySoap" />
                </basicHttpBinding>
              </bindings>
            <client>
                <endpoint address="http://localhost:4080/orderInfo.asmx" binding="basicHttpBinding"
                    bindingConfiguration="orderInfoSoap" contract="ServiceReferenceOrderInfo.orderInfoSoap"
                    name="orderInfoSoap" />
                <endpoint address="http://localhost:4081/product.asmx" binding="basicHttpBinding"
                    bindingConfiguration="productSoap" contract="ServiceReferenceProduct.productSoap"
                    name="productSoap"/>
                <endpoint address="http://localhost:4083/ready.asmx"
                    binding="basicHttpBinding" bindingConfiguration="readySoap"
                    contract="ServiceReferenceReadyInitialize.readyInitializeSoap"
                    name="readySoap" />
            </client>
        </system.serviceModel>
    	
    </configuration

    Regards Markus


    Saturday, December 7, 2019 11:43 AM
  • Hi,
    Ok, I think you can call the service by using the automatically generated configuration. generate the client proxy, call the service and so on.
    ServiceReference1.WebService1SoapClient client = new WebService1SoapClient();
                var result=client.HelloWorld();
                Console.WriteLine(result);

    When you reference the DLL in your main project, we need to copy the system.servicemodel section to the configuration in the main project, then instantiate the client proxy to call the service.
    If we use the channel factory to call the server, we needn’t to copy the system.servicemodel section to the main project. 
    Take the first example as an example.
    BasicHttpBinding binding = new BasicHttpBinding();
                Uri uri = new Uri("http://localhost:4080/orderInfo.asmx");
                ChannelFactory<WebService1Soap> factory = new ChannelFactory< orderInfoSoap>(binding, new EndpointAddress(uri));
                WebService1Soap service = factory.CreateChannel();
    //call the practical method.
                var result = service.HelloWorld(new HelloWorldRequest());
                Console.WriteLine(result.Body.HelloWorldResult);
    

    Feel free to let me know if there is anything I can help with.
    Best Regards
    Abraham
    Monday, December 9, 2019 10:08 AM
    Moderator
  • Hello Abraham,

    BasicHttpBinding binding = new BasicHttpBinding(); Uri uri = new Uri("http://localhost:4080/orderInfo.asmx"); ChannelFactory<WebService1Soap> factory = new ChannelFactory<orderInfoSoap>
    (binding, new EndpointAddress(uri));
    WebService1Soap service = factory.CreateChannel();

    And for binding I can set the timeout, if needed or the default value is not enough.

    Right?

    Best regards Markus

    Monday, December 9, 2019 11:38 AM
  • Hi,

    Yea, you could also directly modify the configuration file when migrating the System.servicemodel section to the main project. Besides, certain properties of the binding are only valid on the server-side.

    <bindings>
          <basicHttpBinding>
            <binding name="WebService1Soap" sendTimeout="00:10:00" closeTimeout="00:10:00">
            </binding>
    



    https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/configuring-timeout-values-on-a-binding
    Feel free to let me know if there is anything I can help with.
    Best Regards
    Abraham

    • Marked as answer by Markus Freitag Thursday, December 12, 2019 6:02 PM
    Tuesday, December 10, 2019 5:36 AM
    Moderator