View Full Version : SpringNet Web Service Exporter
A couple questions about WS exporter:
1. It can only export class file which is fine in most cases. But, in some case, I want to create a class which will consume other web services. For those web service, sometimes I only has wsdl. I usually use the wsdl to create proxy class. Now , since we are getting rid of static proxy class creation, I wonder if there is anyway I can dynamically create server proxy class on top of wsdl instead of class.
2. To consume the web service in client,
I have
<object id="IAccountService" type="Spring.Web.Services.WebServiceClientFactory, Spring.Services">
<property name="ServiceUrl" value="http://localhost/SpringNetService/AccountExporter.asmx" />
<property name="ServiceInterface" value="SpringNetContract.IAccount, SpringNetContract" />
</object>
How can I change the ServiceUrl programmacly?
[/code]
Aleks Seovic
03-15-2006, 10:43 PM
1. Technically, you should be able to create a web service proxy on the server using WebServiceClientFactory and then export that class as a web service using WebServiceExporter. I said technically because I haven't tried it, but I can't think of a reason why it wouldn't work.
2. Because generated proxy class extends SoapHttpClientProtocol, you can safely cast an instance to it and set Url property, as you normally would. By default, Url property is set in the proxy constructor to the value of the ServiceDescriptor.RetrievalUrl, where actual instance of ServiceDescriptor is created based on the value of ServiceUrl property specified in the config file.
That said, I don't really see the need for this -- you will typically use the same URL to generate proxy and to invoke web service, considering the fact that everything is performed at runtime.
Now, if you have a real need to create a proxy at runtime, based on information that cannot be specified in the config file (service URL unknown up front, for example), you can always use WebServiceClientFactory programmatically:
WebServiceClientFactory wsFactory = new WebServiceClientFactory();
wsFactory.ServiceUrl = myDynamicallyDeterminedServiceUrl;
wsFactory.ServiceInterface = typeof(IMyService);
IMyService service = (IMyService) wsFactory.GetObject();
Basically, that's the same thing Spring does under the hood, based on the object configuration.
Regards,
Aleks
Thanks. A follow up of your reply:
1. The problem I am trying to solve is that at web service layer I try to consume another web service created by some other team which they only provide me the wsdl. The question really comes down to how can i use clientproxyfactory to create ws reference based on wsdl since I don't want manually create a proxy using wsdl generator on my service layer
2. The problem is that I want to remove all the calling for ws from web application to a helper class which the helper class will eventually do the ws call instead of web client. The helper class serves kind of business layer. So, client web calls for helper for any data and helper in turn calls the web service for the data. The helper class should not have static URL build into it because it wont work when I move the code from environment to envrironment. So, I need the web client to tell helper class what is serviceurl and helper interrepts and then make a call.
I think you already answered my question, I just tried to explain why I need dynamic ServiceUrl.
Bruno Baia
03-17-2006, 06:49 PM
1. The problem I am trying to solve is that at web service layer I try to consume another web service created by some other team which they only provide me the wsdl. The question really comes down to how can i use clientproxyfactory to create ws reference based on wsdl since I don't want manually create a proxy using wsdl generator on my service layer.
Yes, that's the contract-first approach.
That's the subject of this topic :
http://forum.springframework.net/viewtopic.php?t=318
One solution is to implicity create objects expected by the WebServiceClientFactory like i explain here :
http://forum.springframework.net/viewtopic.php?p=1583#1583
Another solution that we are investigating is an explicit way to do that :
http://forum.springframework.net/viewtopic.php?t=339
2. The problem is that I want to remove all the calling for ws from web application to a helper class which the helper class will eventually do the ws call instead of web client. The helper class serves kind of business layer. So, client web calls for helper for any data and helper in turn calls the web service for the data. The helper class should not have static URL build into it because it wont work when I move the code from environment to envrironment. So, I need the web client to tell helper class what is serviceurl and helper interrepts and then make a call.
I think you already answered my question, I just tried to explain why I need dynamic ServiceUrl.
You can define multiple WebServiceClientFactory in your config file and then pick the one you want with the id :
<object id="AccountService1" type="Spring.Web.Services.WebServiceClientFactory, Spring.Services">
<property name="ServiceUrl" value="http://localhost/SpringNetService/AccountExporter1.asmx" />
<property name="ServiceInterface" value="SpringNetContract.IAccount, SpringNetContract" />
</object>
<object id="AccountService2" type="Spring.Web.Services.WebServiceClientFactory, Spring.Services">
<property name="ServiceUrl" value="http://localhost/SpringNetService/AccountExporter2.asmx" />
<property name="ServiceInterface" value="SpringNetContract.IAccount, SpringNetContract" />
</object>
etc...
Or using external configuration files :
<context type="Spring.Context.Support.WebApplicationContext, Spring.Web">
<resource uri="~/Config/ProductionServices.xml" />
<resource uri="~/Config/TestServices.xml" />
</context>
-Bruno
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.