The code generated in the "Service references" folder contains 2 cs-files.
The generated class seems to inherit from
"Microsoft.Dynamics.IntegrationFramework.WebService.WebReferenceBase" that
does not expose any constructor that allows for the endpoint address to be
changed. So, my question is: is it in any way possible to achieve what I am
looking for without having the customers change the app.config?
/Jonas
Create .net assembly that calls web service. URI to be passed as a parameter.
In VS you can create endpoint manually based on URI. You need to add service
reference to the project. Here is an example using basic authentication
(replace ... with your service name):
using System.ServiceModel;
<...>
void callService(string parmURI, string parmUsername, string parmPassword)
{
EndpointAddress address = new EndpointAddress(parmURI);
BasicHttpBinding binding = new
BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
binding.Security.Transport.ClientCredentialType =
HttpClientCredentialType.Basic;
ChannelFactory<...Service....Channel> factory = new
ChannelFactory<...Service....Channel>(binding, address);
factory.Credentials.UserName.UserName = parmUsername;
factory.Credentials.UserName.Password = parmPassword;
...Service....Channel service = factory.CreateChannel();
...Service....Request request = new ...Service....Request();
// assign parameters if there are any
service.UpdateCompleted(request);
}
<...>
So you can have an URI defined in AX parameter table, so user can easily
change it.
Hope it helps.
Reagrds,
Jack
I have got the issue and made the following solution:
str endPointAddress = 'http://localhost/Hello";
MyWebService.HelloASMXSoapClient soapClient;
ServiceConfiguration conf = new
ServiceConfiguration();
;
conf.configureServiceReference('MyWebService', endPointAddress);
soapClient = new MyWebService.HelloASMXSoapClient(endPointConfigurationName);
With this class I can change the endPointAddress dynamically.
It is changing the config file.
Greetings,
Rob Berghout
Code:
class ServiceConfiguration
{
#Aif
#File
}
void configureServiceReference(str webReferenceName, str endPoint)
{
//SysReference::configureServiceReference(webReferenceName);
SysReference sysReference;
;
// Create SysReference object
sysReference = SysReference::newFromReferenceName(webReferenceName);
if (sysReference == null || !sysReference.parmServiceReference())
{
throw error(strfmt("@SYS118070", webReferenceName));
}
// Configure the service reference
this.configure(sysReference.parmDotNetCodeNamespace(), endPoint);
}
public void configure(AifDotNetCodeNamespace _codeNamespace, str endPoint)
{
FilePath serverConfigFile;
List filesToCopy = new List(Types::String);
Microsoft.Dynamics.IntegrationFramework.WebService.AppDomainCache
appDomainCache;
ApplConfig webServiceConfig;
;
serverConfigFile = AifWebReferenceUtil::getWebReferenceRootDir() +
_codeNamespace + #FilePathDelimiter + #WcfClientConfigName;
webServiceConfig = new ApplConfig(serverConfigFile);
webServiceConfig.paramInsert("endpoint address", endPoint);
// changing other parameters
webServiceConfig.paramInsert("openTimeout", "00:20:00");
webServiceConfig.paramInsert("receiveTimeout", "00:20:00");
webServiceConfig.paramInsert("sendTimeout", "00:20:00");
webServiceConfig.paramInsert("maxBufferSize", "65536000");
webServiceConfig.paramInsert("maxBufferPoolSize", "52428800");
webServiceConfig.paramInsert("maxReceivedMessageSize", "65536000");
webServiceConfig.process();
filesToCopy.addEnd( #WcfClientConfigName);
AifWebReferenceUtil::copyServiceReferenceToAOS(_codeNamespace,
filesToCopy);
CodeAccessPermission::revertAssert();
new InteropPermission(InteropKind::ClrInterop).assert();
appDomainCache =
Microsoft.Dynamics.IntegrationFramework.WebService.AppDomainCache::get_Instance();
if (appDomainCache)
{
appDomainCache.Remove(_codeNamespace);
}
CodeAccessPermission::revertAssert();
}
class ApplConfig
{
str m_filename;
str m_regel;
TextIO m_fileRead;
TextIO m_fileWrite;
container m_nameValues;
container m_newLines;
str m_newLine;
}
void new(str filename)
{
m_filename = filename;
}
void paramInsert(str name, str value)
{
;
m_nameValues += [name, value];
}
void process()
{
int i;
str name, value;
FileIOPermission fileIOPermission;
container data;
;
fileIOPermission = new
FileIOPermission(m_filename,SysDataExpImp::readWrite2Mode(ReadWrite::read));
fileIOPermission.assert();
m_fileRead = new TextIO(m_filename,
SysDataExpImp::readWrite2Mode(ReadWrite::read));
m_fileRead.inFieldDelimiter('\n');
while (m_fileRead.status() == IO_Status::Ok)
{
data = m_fileRead.read();
if (conLen(data)>0)
{
[m_regel] = data;
for (i=1; i<=conLen(m_nameValues); i+=2)
{
[name] = conPeek(m_nameValues, i);
[value] = conPeek(m_nameValues, i+1);
this.setParam(name, value);
}
m_newLines += [m_regel];
}
}
this.saveFile();
}
private void saveFile()
{
FileIOPermission fileIOPermission;
int i;
;
fileIOPermission = new
FileIOPermission(m_filename,SysDataExpImp::readWrite2Mode(ReadWrite::write));
fileIOPermission.assert();
m_fileWrite = new TextIO(m_filename,
SysDataExpImp::readWrite2Mode(ReadWrite::Write),850);
// m_fileWrite.inFieldDelimiter('\n');
for (i=1; i<=conLen(m_newLines); i++)
{
m_newLine = conPeek(m_newLines, i);
m_fileWrite.write(m_newLine);
}
}
private void setParam(str variable, str value)
{
int lenRegel;
int pos, posFirst, posLast;
;
lenRegel = strlen(m_regel);
if (strScan(m_regel, variable, 1, lenRegel))
{
pos = strScan(m_regel, variable, 1, lenRegel);
posFirst = strFind(m_regel, '"', pos, lenRegel);
posLast = strFind(m_regel, '"', posFirst+1, lenRegel);
m_regel = substr(m_regel, 1, posFirst) + value +substr(m_regel,
posLast, lenRegel);