views:

102

answers:

1

I have been handed a wsdl file + a number of xsd type definition files - the service I need to code against is not ready yet and I need to put together a fake service (so called a stub or mock) in order to be ready when the real thing comes along.

My question is - once I get the interface I need to implement from the wsdl, how do I setup dependency injection so that whenever the new service comes along I can add a service reference or a web reference and just edit the spring.net config file to swap in the service I want in the consumer? Is it even possible?

I found this article, specific to WCF, It's pretty good but he seems to have access to the service code and he's doing dependency injection on the service side rather than on the consumer side - in my case I will most likely just get a url, I will have to swap it with the fake local one and go from there.

Also is there a way of doing this only dependent on the way I consume the service but not on the way the service was put together? I mean, I shouldn't care less which technology was used to develop the service as long as I get a url to the wsdl.

Any pointers appreciated!

+1  A: 

Just create an interface which maps to the webservice methods and use that on the client side. It doesn't matter if it's a local service, webservice, or whatever.

I've done what you are trying to do before, you can read about it here.

BennyM
thanks - seems to be right what I am looking for. I guess the config example (<object>...</object>) refers to --> "On the client side a similar approach can be used to consume the webservice using the WebserviceProxy factory in the Spring.Services assembly. Using this class your code can depend upon the service interface instead of the proxy class itself."? You provide the example right after saying "if you control both sides", but I don't so, not being particularly familiar with spring.net, I am a bit confused. Could you expand on that?
JohnIdol
just noticed you've got an example in there - pretty neat and using MVP as well (I am using it too). I see you're linking to a ascx service - would it make a difference it was a svc or a wsdl or would it work exact same way?
JohnIdol
You can feed it a wsdl file too, just change the ServiceUri of the Webservice proxy factory.<property name="ServiceUri" value="http://myServer/Calculator/calculatorService.asmx"/> <!--<property name="ServiceUri" value="file://~/calculatorService.wsdl"/>-->There's more info in the documentation. http://www.springframework.net/doc-latest/reference/html/webservices.html
BennyM
So in your case I'd create an interface with the service methods and use the wsdl file in the proxyfactory.Be sure to map the methods correctly, naming and parameters.
BennyM
sounds great - so basically as long as the interface methods match the web methods (or operationContract methods) I should be OK? I see that in your example your service implements the same interface that you use in the client (IProductService), but I have no access to the service itself
JohnIdol
You're ok, it doesn't matter that this specific interface is not on the server side. You're sharing the contract, not the code.Just create an interface and match the methods.
BennyM
Cool - thanks, I'll let you know how it goes :)
JohnIdol