I recommend using a fixed port number for WCF web application service host projects during development, so that you can add svcutil command lines to a batch file which can be re-run each time a service contract changes. To ensure the service is hosted properly, try browsing to the service URL before attempting to generate the proxy.īelow is an example svcutil command line. Your service also needs to be hosted on IIS, IIS Express (Microsoft WebMatrix) or Cassini (Visual Studio development web server) before you can generate proxies. One important point about svcutil is that it should be run using the Visual Studio command prompt. This is a great help in differentiating between types which are defined in the service layer when you are using them in client code. Among the many command line switches that are available for svcutil, you can specify a namespace for the auto-generated proxy types. NET service model metadata tool svcutil which will generate the necessary proxy code and service configuration for us. So now we have a service and data contract class but how can the client access them? One option is to use the. The DataContract and DataMember attributes which decorate the class enable the WCF data contract serialiser to convert it to and from XML. The UserRegistration type is a simple DTO (data transfer object) used to transfer data between a client application and the service. Generating service proxies is all about the service contract (interface) – not the service implementation. I haven’t shown the service implementation here, but you can just assume that it exists. The ServiceKnownType attribute is used to tell the WCF data contract serialiser which concrete type (in this case UserRegistration) implements the IUserRegistration interface. I’ll start with a simple WCF service contract with a single operation called RegisterUser. The following example is based on a WCF web application project using HTTP binding, but it would work just as well with a self-hosted service using another transport such as TCP. via a shared assembly) then I recommend using the WCF ChannelFactory class instead of using svcutil.exe because it makes life a lot easier (see my post on how to use ChannelFactory to create re-usable proxy classes). However, if you do have direct access to the service contract declarations (e.g. If it returns a WSDL XML document in the response, then metadata is enabled and you can use SvcUtil. To check if service metadata exchange (mex) is enabled, browse to the service and put a ?wsdl query string parameter at the end of the URL path. This is most appropriate when you want to consume a third party service and don’t have access to the service contract type declarations, but you can obtain a service metadata WSDL document from the service. There are various ways to make calls to a WCF service from client code but this particular example uses the Microsoft svcutil.exe proxy generation tool.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |