How to change the wsdl:definitions name attribute on a BizTalk service - wcf

I've published schema as a wcf service, choosing WCF-CustomIsolated with a binding type of customBinding. I can now browse to the web service and look at the wsdl. All good so far, but I do have some questions about how I configure the receive location to make some specific changes in the wsdl:
Change the wsdl:definitions name attribute. It is set to BizTalkServiceInstance by default
Change the wsdl:service name attribute. It is also set to BizTalkServiceInstance by default

For this you need either implement custom WCF wsdl extension or write your own wsdl and use that for contract. This link will give you some idea. Custom Types in wsdl. Although this link is for faults however it will give you an idea.

On your WCF-Custom receive port, add the WCF behavior serviceMetadata.
Add the path to your custom WSDL file (you need to copy it in c:\inetpub\wwwroot\\your.wsdl for example).
FYI: in this case your path would be "../your.wsdl" for example.
Then, set httpGetEnabled to true.
Edit your wsdl as you like.

Related

Is there any way to hide the operation contract tag in the wsdl for WCF soap web service?

For example, if I have a operation contract as GetData() I dont want it to be in wsdl but the method should be accessible by client using Action Attribute and would be able to be consumed.
So the client should just "know" that the service method is there and how to call it?
Anyway no, you can't do that. Save the generated WSDL and XSDs, modify them to remove the information you want to remove and then supply these WSDL and XSD to the client.

How do I change the CollectionType on a service proxy generated with svcutil.exe?

Ok, so I have implemented my services, created a new WCF service website to host my services in IIS and used svcutil to export metadata to the .xsd and .wsdl files. From these files I generated the service proxy.cs and .config files and added them to the client.
One of my service operations returns a Generic List to the client though. I know how to change the CollectionType of the deserialized DataType by configuring the Service Reference when it has been added from visual studio (Add Service Reference), but how do I change (or set during the creation of the proxy with svcutil(?)) the CollectionType?
There is a switch /collectionType:<type> you can add to specify the type. See the MSDN docs for all the detail.

How do expose my own meta data in WCF service?

Rather than exposing the system generated meta data I'd like to provide my meta data which is kept it a text file (say) on the server. I guess this means responding to the HTTP GET request http://[service address]?wdsl.
You could simply turn off metadata export (remove serviceMetadataBehavior or set its httpGetEnabled flag to false) and then put your WSDL document at a URL that makes sense for your app (?wsdl is a WCF / ASMX convention but its not a standard)
This is pretty easy if you are using IIS hosting but would need a REST endpoint for Self Hosting
You can develop a custom MetaExporter and then find ServiceMetadataBehavior, in that behavior, you can override the default MetadataExporter.
Therefore in your MetaExporter, you can do anything you want.

Is there any good material about the working mechanism of IIS hosting WCF web service?

It is just magic that I put some file in my site's Bin folder and place a svc file to point to some assembly pointing to my service type. And then, I could magically Add Service Reference to the url like this:
http://www.myserver.com//xxx.svc
I really want to know how what happens from my click "Add Service Reference" to the proxy is generated properly. What does the IIS do during this period?
It's not really magic - it's metadata exchange ! :-)
When you do a Add Service Reference in Visual Studio, behind the scenes, that service endpoint specified by the svc file is interrogated for its metadata. This is basically similar to a WSDL (Web Service Description Language) file - a machine-readable description of your service, its methods, what parameters they expect etc. - and a XSD (XML schema) that - again in machine-readable form - defines the parameter types used.
Based on those two pieces of information, the WCF client side import can create C# or VB.NET classes that
mirror the exact service implementation on the service side - same method names, same parameters expected and returned
create the necessary data classes - again in C# or VB.NET - based off of the XML schema file
So in the end - it's really not magic. It's the beauty of self-describing services and a bit of code generation that reads that metadata and creates client-side proxy classes from that metadata description
If you're interested in more details about metadata, read the MSDN docs on WCF metadata - quite extensive and in-depth.
As marc_s stated, the "Add Service Reference" button runs a tool that collects the metadata from the service, and generates client code from it.
I just wanted to add that if you want to view that metadata (WSDL) yourself, you can just add "?wsdl" to your URL:
http://localhost/MyService.svc?wsdl
One WSDL document will chain to many others, so you would have to make several requests to dig through them all, but it is interesting to see how the data types and contracts are transmitted.
Also, if you want to prevent other people from automatically generating a client to your service, you can disable the WSDL by removing the "mex" (Metadata EXchange) endpoint from your WCF configuration.

Can I add a Service Reference with netTcpBinding in WCF?

Is it possible to add a service reference in visual studio, which generates the local proxy class to call the WCF service when using the netTcpBinding?
As I understood it, the service reference method requires a WSDL to be exposed by the service, which is only supported by the http bindings no?
Perhaps, could I add the service reference locally in development, but then switch the configuration to use nettcp at runtime in production?
The reason I am asking is because I am hosting in a windows service (server 2003, so no WAS, and can't use IIS). And we are unable to change the permissions to do the HTTP namespace reservation ... so we can't use the HTTP bindings. NetTcp works, but in this specific case the object graph we're passing back and forth involves objects generated in the service by an EDMX model ... so we can't share it in a contract assembly.
Thanks in advance!
Simply add a binding using mexTcpBinding.
Is it possible to add a service reference in visual studio,
which generates the local proxy class to call the
WCF service when using the netTcpBinding?
Yes, most definitely!
As I understood it, the service reference method requires a WSDL
to be exposed by the service, which is only supported by the http bindings no?
No, definitely not - WCF metadata (either its own specific format, or exposed as WSDL / XSD files) is definitely available for all SOAP-based calls - regardless of their transport.
Can you show us what you have, in terms of server-side config? Most likely, you're just missing a little config setting or something - if we see what you have, we might be able to pinpoint that and help you more!
All bindings are exposed though WSDL. If you add the NETTCP bindings svcutil will atuo generate the client correctly. I haven't used it in the ADD reference in VS as i have always preferred to generate the class with svcutil.