Hi everybody and pardon me in advance if that question has already been covered but I couldn't find a precise answer before.
My situation is: I have developed a library that has a service reference (because it calls a SOAP Web Service). The web config has some parameters set like proxy and so on. I understand that the client has to know how to invoke this web service (address...) even though there's a proxy class between the client and the service reference.
So let's code an example:
public class Example
{
public string Foo(string param1, string param2)
{
try
{
using (var service = new EU.ServiceTypeClient())
{
// implementation here
var element = service.GetSomething(param1, param2)
...
}
}
}
}
This class has the service reference and the app.config
The client (console for example) has to know that configuration as well. Therefore what you tipically do is to copy that file in the .NET solution or write codebehind.
var binding= new BasicHttpBinding(BasicHttpSecurityMode.None);
binding.Name = "BasicHttpBinding_YourName";
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
var endpointAddress = new EndpointAddress("http://blahblah");
var client= new ServiceTypeClient(basicHttpbinding,endpointAddress);
...
And if I use a proxy class, put in the middle, that recalls Example Class (let's say it has a property Example) and it's been instantiated by console app, it has to own that configuration as well. The whole class hierarchy has to do it, otherwise an exception would have been thrown with the error message "Could not find endpoint element with name..."
Therefore, my question is: because I have to make this DLL available to a client developed in VB6, how can it consume this? Web service methods have signature with a couple of parameters, as you saw before.
- Is it possible to "inject" other parameters that describe the configuration file?
- Or is it possible to load a configuration file in VB6 and act like it were a .NET client?
- Or is it possible to write codebehind to do that? Any suggestions?
Request:
<xsd:element name="request">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="idCode" type="xsd:string"/>
<xsd:element name="number" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Response:
<xsd:element name="response">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="idCode" type="xsd:string"/>
<xsd:element name="number" type="xsd:string"/>
<xsd:element name="requestDate" type="xsd:date"/>
<xsd:element name="valid" type="xsd:boolean"/>
<xsd:element maxOccurs="1" minOccurs="0" name="name" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="address" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="myBinding" useDefaultWebProxy="true"/>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://blahblah/myservice"
binding="basicHttpBinding" bindingConfiguration="myBinding"
contract="EU.myServicePortType" name="myServicePort" />
</client>
</system.serviceModel>
<system.net>
<defaultProxy useDefaultCredentials="true" />
</system.net>
</configuration>
Thanks