Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Changing endpoint address of external web service

49 views
Skip to first unread message

Jonas

unread,
Sep 21, 2009, 2:03:01 AM9/21/09
to
Hi
I have created a web service that will be placed on a couple of servers and
called from Ax. I have successfully added a reference to it in Ax. However,
only one constructor has been generated - the one that takes the endpoint
name as an argument. If the same web service would have been referenced in
Visual Studio, I would also have had the option to pass an address argument.
The only way to change the endpoint address seems to be in the app.config of
the reference, but I really would like my customers to configure this inside
Ax without having to change the app.config of the reference. (They could use
the Service Configuration Editor, but that means that they would have to
install an SDK and fool around inside the AOT and I am not sure that this is
the most appropriate approach.)

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

Jack

unread,
Oct 7, 2009, 7:30:01 AM10/7/09
to
Here is what you can try:

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

Berghout@discussions.microsoft.com Rob Berghout

unread,
Nov 25, 2009, 8:46:06 AM11/25/09
to
Hello,

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);

0 new messages