Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Web Service change wsdl name and targetNamespace

All,

I'm a little new to WCF over IIS but have done some ASMX web services before. My WCF service is up and running but the helper page generated by the web service for me has the default names, i.e. the page that says:

You have created a service.

To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:

svcutil.exe http://localhost:53456/ServicesHost.svc?wsdl

In a standard ASMX site I would use method/class attributes to give the web service a name and a namespace. When I click on the link the WSDL has:

<wsdl:definitions name="SearchServices" targetNamespace="http://tempuri.org/" 

i.e. not the WCF Service Contract Name and Namespace from my Interface. I assume the MEX is using some kind of default settings but I'd like to change them to be the correct names. How can I do this?

like image 641
Graham Avatar asked Apr 01 '10 14:04

Graham


People also ask

What is WSDL WCF?

WSDL stands for Web Service Description Language. The WCF service exposes the WSDL document for the clients, to generate proxies and the configuration file. The WSDL file provides the following information for the consumers of the WCF service.

What is Web service Svc?

SVC, or . svc, is a computer file extension utilized by Microsoft's Windows Communication Foundation to symbolize a service hosted by Internet Information Services.


2 Answers

Add this to your service contract

[ServiceContract(Namespace = "http://some.com/service/", Name = "ServiceName")]

Add this to your service implementation

[ServiceBehavior(Namespace = "http://some.com/service/")]

Add this to your web.config

<endpoint binding="basicHttpBinding" bindingNamespace="http://myservice.com"....
like image 67
Nix Avatar answered Oct 17 '22 06:10

Nix


Actually, it should be put on ServiceBehavior:

[ServiceBehavior(Namespace = "http://some.com/service/", Name = "ServiceName"]

Then WSDL name will be changed.

like image 39
neolei Avatar answered Oct 17 '22 05:10

neolei