How to change the WCF Service Url? - wcf

I have a WCF 3.0 service which has been configured with BasicHttpBinding and has been deployed and hosted in IIS.
I can access my service using the below url:
http://mydomain.com/subfolder1/subfolder2/myservice.svc/basic
"basic" at the end of the address is the relative address of the end point and "/subfolder1/subfolder2" is where the myservice.svc file has been physically deployed to:
<endpoint address="basic" binding="basicHttpBinding"
contract="Company.MyService.Implementation.Contracts.IMyService">
</endpoint>
How to configure the settings so that I can access my service using the below url without specifiying the .svc path:
http://mydomain.com/myService/basic
Thanks,

In fact, it is not the responsability of your service. You should build "address-less" service and not specify one absolute in the config.
Your question is relevant to web hosting under IIS. There is a huge difference between the physical path (where you deploy) of your service and the virtual path (where client access it).
In your example, you simply need to create a new web application under http://mydomain.com/ and publish your service. subfolder1 seems to be a virtual directory of an existing web site. Just create the web app here, with IIS manager.

Related

Regarding WCF endpoint address attribute

being new to wcf i often stuck to write endpoint address in config file. sometime i just could not understand what address i should write in endpoint at host end where service will be running. here is one sample endpoint entry....please have a look.
<endpoint address="net.tcp://localhost/ServiceModelSamples/Service1.svc"
binding="netTcpBinding"
contract="ServiceReference1.IService1">
</endpoint>
<endpoint address="net.tcp://localhost/ServiceModelSamples/service"
binding="netTcpBinding"
contract="ServiceReference1.IService1" />
i have couple of question on endpoint address
1) when i should write endpoint address like this way
net.tcp://localhost/ServiceModelSamples/Service1.svc
i guess when we will host our service in IIS then we need to write endpoint address like above one where we need to write our svc file name.
am i right?
2) just see the below address
address="net.tcp://localhost/ServiceModelSamples/Service1.svc"
what is ServiceModelSamples do i need to mention it?
3) suppose i develop wcf service with wcf service application template and host that service in win form apps then how our endpoint address would look like below one
address="net.tcp://localhost/ServiceModelSamples/service"
do i need to write ServiceModelSamples our project name folder or we can remove it from
address like address="net.tcp://localhost/service"
it is very important for me to know that do i need to write our project folder name like
ServiceModelSamples
4) when we host wcf service in win form apps then do i need to specify our svc file name with extension.
5) specifically guide me what address i need to write when we host our service in win form apps.
my all above question may sounds very stupid but i have really confusion about address in
endpoint. i have no there way to put question here. So please have a look at my 5 points and guide me. thanks
I think your confusion comes from the differences between IIS Hosting and custom hosting.
When you use IIS to host the service, the service behaves this way:
A base address is assigned to the service automatically depending on where the service is hosted in IIS. It uses the same address mapping that a web site uses.
The service layer needs to have .svc files to expose service instances through IIS. Those service files are just mapping files that help exposing on IIS.
So to fill the address to a service hosted in IIS from the client you need to:
Find out the address that has been assigned by IIS.
Complete that address with the Service.svc file name that you want to point to.
However when using custom hosting (through ServiceHost) the service address is totally goberned by the service configuration file:
The service can configure a base address to all its endpoint via the baseAddresses setting
All endpoints can have a full address or relative address. If relative address is used then the resulting endpoint address will be the baseAddress + endpoints relative address.
When custom hosting you have complete control over the service addresses, so you don't have any of the constraints that you must follow on IIS.

how to use WCF for web application

i need to use WCF Service with in my web application.
I ama new to wcf.
i created the service and add the service reference in my web application.
It shows the http:localhost in end point address.
endpoint address="http://localhost:52123/GeneralService1.svc"
i am confused to use the local host for access the wcf in web.
Is there any way to communicate with wcf / how to enable the connection.
Thanks in Advance
Pooja
A WCF endpoint has its ABC.
A - Address
B - Binding
C - Contract
<endpoint address="" binding="wsHttpBinding" contract="WcfService2.IService1">
You can change the address, by putting the Url of your deployment server, where the service would be hosted in production.
Read this for more details of WCF endpoint ABC
You can modify this address in the web.config file, to the url, while deployment.

Host WCF web service in IIS

I've created a web service, and I hosted in IIS, it worked perfectly.
But when setting up a website in IIS, there's a field to bind the physical path to the WCF project folder
My question is what file in that folder are needed for IIS to host the service?
Because I need to create websites in clients' server, so I don't want my code to be seen.
Thanks

How to configure the wcf service to view the test page without pointing to svc file in address box?

I have created a working wcf service. I have come a cross a page regarding wcf services
which describes the process for eliminating default wcf service page.
It is here https://github.com/geersch/WcfServiceMessage
Except for the things the author of this page is describing, I have one question.
How has he managed to configure the IIS or Web.config to host page with the address: http://localhost:8732/HelloWorld/ ?
At home, the only address I see my service at is: http://localhost:8732/MyServiceName.svc
(with svc extension)
How has he done it that the endpoint address: "HellowWorld" is used?
Thanks!
The WCF service endpoint is not actually a file. The total url itself is what the server recognizes as something to service, so the HelloWorld piece is just as good as HelloWorld.svc.
This is a difference between IIS hosted service and Windows or Visual Studio service host (cassini). In iis, you do have to specify a file that ends with svc and make that extension known. In iis you can also set a svc file as the default file to open if a specific directory is opened. that way you can achieve the same behavior.

404 BadRequest exposing WCF service through external IP using IIS host headers

We host a WCF webservice on Windows Server 2003. This server only has 2 internal IP's. We want to expose the service externally. This is done through the firewall that maps an external IP to the service.
So, I would need to modify the service to display that external IP for the internal links. This is not an issue since it should only be used externally.
Changing the Host Header value in IIS gives a 'Bad Request (Invalid Hostname)' response from IIS. I also added an 'address' value to the endpoint entry in the web.config ... but it sill just points to the internal machine name. Any ideas?
edit: I can verify that IIS7 has the exact same behaviour. Address didn't work. Different hostname gave Invalid Hostname error. Is there seriously no way to present a different (fictive) IP? :/
edit2:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicAnonymous">
<security mode="None"/>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="Extended">
<serviceMetadata httpGetEnabled="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</serviceBehaviors>
</behaviors>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="false" logMessagesAtServiceLevel="false" logMessagesAtTransportLevel="true" maxMessagesToLog="3000"/>
</diagnostics>
<services>
<service behaviorConfiguration="Extended" name="AnCWCFWebService.ProductInfoProvider">
<endpoint address="" binding="basicHttpBinding" name="ASMX" bindingConfiguration="BasicAnonymous" contract="AnCWCFWebService.Interfaces.IProductInfoProvider"/>
</service>
</services>
</system.serviceModel>
404 BadRequest Due to IIS Configuration...
If you are receiving a 404 BadRequest error from IIS after attempting to modify host headers in IIS, this is common, but there is a fix!
Fix By Making IIS Configuration Changes
How can WCF support multiple IIS Binding specified per site?
Fix By Making WCF Code Modifications
Alternatively, the following article explains how one developer solved this issue with a combination of configuration and code:
Well, that was fun! An adventure in WCF, SSL, and Host Headers
http://geekswithblogs.net/rakker/archive/2008/07/03/123562.aspx
The article references two important links...
The first one explains how to properly set the host headers in IIS:
Configuring Server Bindings for SSL Host Headers (IIS 6.0): http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/8d9f2a8f-cd23-448c-b2c7-f4e87b9e2d2c.mspx?mfr=true
After getting host headers working, you'll find that...
"you can't have more than one host
header for IIS or wcf will break"
The solution to working around this limitation is found within this article, and there is also a comment on the GeeksWithBlogs.net article above that provides an enhanced variation:
WCF: This collection already contains
an address with scheme http
If you are still experiencing trouble, let us know in the comments below...
If the Service is Not Working...
My experience with WCF is that it is very tricky at times, especially with configuration. If one is following best practices and not doing anything non-standard, the great majority of deployment problems are the result of a botched configuration file.
In theory (not so much in practice, due to architectural differences), setting up a WCF service on IIS should be no different than setting up a typical virtual directory and corresponding application for web application or for an ASMX web service.
Therefore, I recommend that if this is the first WCF service you are exposing to the Internet, follow the same simple approach you would take when exposing your first website. Basically, create a new sample "WCF Service Application" (this is available in the Add New Project dialog, under the Web section of C# or VB).
Once you have it working, follow your deployment practices to move it into a production sandbox and test it locally. This sandbox would preferably already have some web sites or web services installed and known to be accessible from the Internet, in order to eliminate any doubt about the typical network configuration issues. If you have a sample ASMX web service that is already successfully exposed on the Internet from that server, that would be best.
Next, try testing the the ASMX and the WCF services from web browser, both locally on the server, internally on other desktops and then finally externally.
Testing URLs
We want to test accessing the standard SVC and ASMX file from the web browser in all the varieties of URL flavors that are available and relevant. The results should be similar, with summary page about he service rendering in the window. The difference will be that the ASMX web service's summary will likely allow you to execute the web methods on the service if that feature has not been disabled in the web.config file.
Compare the results of browser fetches of the following styles of URLs...
http://localhost/WcfService1/Service1.svc
http://localhost/WcfService1/Service1.asmx
http://MachineName or MachineFQN/WcfService1/Service1.svc
http://MachineName or MachineFQN/WcfService1/Service1.asmx
http://MachineLocalIP#1/WcfService1/Service1.svc
http://MachineLocalIP#1/WcfService1/Service1.asmx
http://MachineLocalIP#2/WcfService1/Service1.svc
http://MachineLocalIP#2/WcfService1/Service1.asmx
http://ExternalIP/WcfService1/Service1.svc
http://ExternalIP/WcfService1/Service1.asmx
All of these tests should return similar results.
Testing Service Methods
If you feel like it, go head and test some web methods on the ASMX web service for any of the tested URLs, from the web browser. You'll soon see that we can test ASMX web services a different way also...
Next we'll test web methods on both the WCF service and the ASMX web service by using the WcfTestClient.exe application that is found in the Visual Studio 2008 distribution (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE).
You will need to add the services through the File->Add Service menu item, typing in the URL above for each service URL that you wish to test. Make sure to include the filename of the SVC and ASMX files. If all is well, the MEX endpoint that is enabled by the "httpGetEnabled" attribute of the <serviceMetadata/> element in the web.config file will return the data that is necessary for the utility to operate, thereby populating the tree with the inventory of our service methods like this:
From this point, it will be useful to refer to the following to resources:
WCFTestClient: http://msdn.microsoft.com/en-us/library/bb552364.aspx
What's New for WCF in Visual Studio 2008: http://msdn.microsoft.com/en-us/magazine/cc163289.aspx
Conclusion
If you make it this far, then I do not expect any other issues and you should now attempt to compare the setup of the samples to the WCF service that you are attempting to publish to the Internet, and hopefully the differences will be obvious.
Remember to treat the WCF service like an ASMX web service during you diagnostics, assuming that the web.config is known to be set up correctly.
If you are still unable to make things work, check this guide for further technical advice:
Deploying an IIS-hosted WCF service: http://msdn.microsoft.com/en-us/library/aa751792.aspx
Finally, if all else fails, just wrap your WCF service in an ASMX web service:
How to: Expose WCF service also as ASMX web-service: http://kjellsj.blogspot.com/2006/12/how-to-expose-wcf-service-also-as-asmx.html
You just need to configure your host header in the IIS so that the links in the WSDL references will use the donmain name rather local machine name.
Check out
Steps to configure IIS host header so that WCF will use domain name in WSDL references.
Why not just assign a new IP address to the server instead of messing around with hostnames? A Windows Server can have multiple IP addresses for the same NIC.
Here is an article that talks about it.