0

I created a class library project in Visual Studio (C#). I added a service reference in that project for a WCF service and created a class and functions to consume that service reference.

Then I created console application project in Visual Studio (C#) to test the above class library project but it was throwing an error. While looking for the solution I found that I need to copy the <system.servicemodel> from app.config of my Class Library project and add it in my test project. I tried this solution and it worked fine.

However, I need to provide this DLL file (only the DLL) to a third party where they will use it. How can I configure my Class Library project that I don't have to manually copy <system.servicemodel> from app.config of class library???

i.e I will only share the DLL with them and they should be able to run it without adding anything extra in app.config on their side.

  • First, as mentioned in the below reply, we could set up the service configuration by either XML file or programming. https://learn.microsoft.com/zh-cn/dotnet/framework/wcf/configuring-wcf-services-in-code https://stackoverflow.com/questions/54579/wcf-configuration-without-a-config-file by the way, you could also call the service by constructing the channel factory instead of adding service reference. https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-use-the-channelfactory – Abraham Qian Feb 26 '19 at 09:00

2 Answers2

1

WCF will take the end point details from app.config by default, but you can also provide them in code:

BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("Your service address here");
var client = new YourServiceClientClass(binding, address);
Zohar Peled
  • 79,642
  • 10
  • 69
  • 121
  • Thanks. This needs to be done inside the DLL right? Because the Service client class in being used inside the DLL only. In my test project, I am only creating object of the class in the DLL. – Usman Javaid Feb 26 '19 at 07:11
0

For this case, you must use the below sample code: In "BasicHttpBinding" class, you can config all of your settings that you configure it on web.config before.

            var binding = new BasicHttpBinding
            {
                Security = new BasicHttpSecurity
                {
                    Mode = BasicHttpSecurityMode.Transport
                },
                AllowCookies = true,
                MaxReceivedMessageSize = 20000000,
                MaxBufferSize = 20000000,
                MaxBufferPoolSize = 20000000,
                ReaderQuotas = new XmlDictionaryReaderQuotas()
                {
                    MaxDepth = 32,
                    MaxArrayLength = 200000000,
                    MaxStringContentLength = 200000000
                }
            };
            var endpoint = new EndpointAddress(account.Url);
            var _client = new online2ServicesSoapClient(binding, endpoint);