I use VS2008, .net 3.5.
There is an external Web Service (it is PHP implementation, but dont mind implementation -.net, java, php,...-).
In my project csproj, I want add Service Reference to WebService and I want use WCF.
When I add Service Reference in VS2008, WCF proxy is created.
Any best practices (patterns and practices) for add service reference (external service) ?
The WCF Proxy Generator (I think the same svcutil command) generates source code like this. Perhaps it will be interesting manages the code generated (ServiceContractAttribute Namespace="http://192.168.50.63/WebService" use IP address, and OperationContractAttribute(Action="http://devservername/webservice/SmoBridge.php/login" use servername).
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://192.168.50.63/WebService", ConfigurationName="ServiceEasyVista.WebServicePortType")]
public interface WebServicePortType {
[System.ServiceModel.OperationContractAttribute(Action="http://devservername/webservice/SmoBridge.php/login", ReplyAction="*")]
[System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, Use=System.ServiceModel.OperationFormatUse.Encoded)]
[return: System.ServiceModel.MessageParameterAttribute(Name="return")]
string login(string SESSION_ID, [System.ServiceModel.MessageParameterAttribute(Name="LOGIN")] string LOGIN1, string PASSWORD, string COMPANY_ACCOUNT);
Update:
the Erwyn’s recommendations about the correct closing of a faulted WCF Channel.
http://bloggingabout.net/blogs/erwyn/archive/2006/12/09/WCF-Service-Proxy-Helper.aspx
Why does ClientBase Dispose need to throw on faulted state? (Or, what's the difference between close and abort?)
http://social.msdn.microsoft.com/forums/en-US/wcf/thread/b95b91c7-d498-446c-b38f-ef132989c154/
check this out:
http://www.sanity-free.com/125/php_webservices_and_csharp_dotnet_soap_clients.html
i think that one is sophisticated technique.
Regards,
Mazhar Karimi
I don't know why there would be any particular best practices around adding a reference. Having said that, the "Refresh Reference" command in Visual Studio (right-click on an existing service reference) sometimes doesn't work too well, so it can be easier to use the svcutil command manually, and have a .bat file in your solution that updates the service reference (svcutil is what "Add Service Reference" is using behind the scenes).
Also, if the service you're referencing is returning an array, you can get WCF to automatically turn it into a generic list (or some other type) - this might make things easier.
Related
I need to create a wsdl file to provide it to a third party. I do not have my web service implemented yet. All I have is a document that tells what operations the web service will support and the input and the return (output) parameters for each operation. I need to create a wsdl before implementing the service. Any ideas on how to approach this? Are there any tools that allow to create wsdls manually? Thanks in advance!
The best way to create a WSDL is let VS create it for you. This can easily be done when creating a WS Application.
So, If you already need to create the interfaces (to pass them to the 3rd party) but just not the implementation - Create the webservice itself (more specifically the interfaces) but instead of implementing, throw a NotImplementedException in all of them.
You can then run the WebService, have it generate the correct WSDL for you (which you can pass to the 3rd party) and all you have left is to implement the methods at your free time.
Just want to ask you to confirm that I'm right (but may be totally wrong :).
Situation: I have a VS2010 Solution with 3 projects A) WCF Library, B) Web Site that host this library C) test application that use the web service. Last I could configure two different ways: adding reference to the WCF Lib or Web Site.
I've discovered that when I'm referencing WCF library directly (some may be remember those endpoints http://localhost:8732/Design_Time_Addresses/...) the configuration of custom servicehostfactory in app.config element
<serviceHostingEnvironment><serviceActivations>..
is ignored.
Since interpretation of serviceHostingEnvironment is responsibility of the host I make an assumption that VS2010 WCF Library Host have such feature - ignore serviceHostingEnvironment? Am I right?
P.S. May be I could ask you to point me the doc where I could find the information about VS2010 WCF library's host.. It seems I should get to know better.
Description of test service host is here. ServiceHostingEnvironment element controls integration with web server = I don't think that any part of this configuration section is used for self hosted services and test host is self hosting.
ServiceActivations element contains file-less activation configuration for web server. That means ability to activate service without physical existence of hosting .svc file. That is something which doesn't make sense in self hosted scenario.
I want to consume a file which is wsdl with VB6 , anyone can help me? Or how can I convert wsdl to proxy class ?
You can look at either Microsoft's SOAP Toolkit or PocketSOAP. Might be best to look at both, but don't despair over the learning curve. Both offer simple approaches for simple situations as well as complex solutions for more complex ones.
First, you have a problem with terminology: you do not want to consume the file. The file is a description of a web service. It is the web service that you want to consume. The WSDL gives you all the information you need to consume it.
There are methods to consume a web service in VB6. In the same way you shouldn't be using VB6, you shouldn't be using any of these methods.
You should use VB.NET to create a small COM component. This component will consume the service by using "Add Service Reference" to create proxy classes. You will be able to use modern tools and techniques to develop and debug this component.
You can then consume the COM component from VB6, just like any other COM component.
Basicly you can use the SOAP moniker like this
Set oProxy = GetObject("soap:wsdl=http://server/folder/service.wsdl")
oProxy.Method "Param1"
You can check out the answers to What is the best way to consume a web service from VB6?
I have a WCF service with a namespace called:
MyCompany.MyApplication.Configuration.ConfigurationHelperService
On the client side I have an assembly called which consumes this service:
MyCompany.MyApplication.Core (this is the default namespace)
When I add the service reference, the namespace I'm asked to specify in the Add Service Reference dialogue ends up getting tacked on the end of the client assembly namespace:
MyCompany.MyApplication.Core.MyCompany.MyApplication.Configuration
.ConfigurationHelperService
Because I'm asked for a namespace at this time it seems natural to specify the name of the remote service namespace. i.e. I'd like to refer to my remote service classes using their namespace MyCompany.MyApplication.Configuration.ConfigurationHelperService because they're technically not part of the client.
My questions are:
What's the rationale behind this, is this something to do with semantics?
Should I try to resist changing this behaviour by modifying the client side generated source to get the namespace I want?
I've lived with this for a long time (you have the same problem with ASMX web service clients) but have never seen a written down explanation why Visual Studio (and I guess svcutil.exe) works this way.
Well, I think you have two choices, really:
if you control both ends of the wire, e.g. you write the server and the client, you could put all the shared items like service contracts, data contracts etc. into a separate assembly and share that between client and server. That way, nothing would be duplicated, and both ends of the communication would refer to the exactly identical items in a given namespace of your choice
get used to the fact that if you add a WCF service reference in Visual Studio, you're basically getting a whole slew of duplication - because if you're not controlling both ends of the communication, that's really all WCF can go on - the metadata exchanged between service and client (through the WSDL or the MEX endpoint on the service). And since this clearly is part of the client, which is completely separate from the service (all they share, typically, are the wire-formats defined in the XML schema - nothing else), its namespace will also be client-oriented. I think this is a (good) feature, and not something I'd try to combat.....
By default, in a SOA world using WCF, the client and the service are totally independant of one another. There's no "remote object" connection or anything like that between the two: the client proxy has a method call happen, bundles up those parameters passed in plus some information what method on the server to call, and serializes it all up into a serialized message (read: a text / XML message, basically). That message is sent across the wire to the server which then handles that message and returns a response.
So this is not just a .NET function call or something - those two pieces of your system are (by default) absolutely independent of one another. Considering that, to me at least, it makes sense that everything the client does will be placed in the client's namespaces - after all, the server could be something totally different, like Java, PHP, a IBM mainframe - you typically don't have any clue what it is (and don't need to).
My new project has a design in which there are number windows services for performing different tasks. I have been given a task to create base class from which all of the windows service will inherit. This base class will perform common functions like creating instances of other windows services by iterating through the config file (may be like Activator.CreateInstance), do event logging on onStart, onStop etc. and may contain some more functionality.
Before I start developing stuff, wondering if there is any pattern already in place or someone has good understanding of how to implement this kind of functionality.
Any help appreciated.
I forgot to mention I am using .Net 2.0 (C#), no option for wcf
Check "A simple windows service to host WCF or WF services", I really like it.
Look in your main method , when you create windows service and you will see that the routine is not call onstart and onstop, you can create each service by createinstance and give it as a paramater to ServiceBase.Run, in your case every service will not appear as a separate service, ServiceController is a great class to start and stop services too, use it if you need