Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I have created a simple test service as below. I want to give the URL to my client as defined in URI Template.
I have hosted the service in IIS.
What will be the url for the below service??????

Please suggest

IService1.svc

[ServiceContract]
    public interface IService1
    {

        [OperationContract]
        [WebInvoke(UriTemplate = "?name={name}", Method = "GET")]
        string checkName(string name);
        
        // TODO: Add your service operations here
    }



IService1.cs

public string checkName(string name)
        {
            if (name == "ABC")
            {
                return "ABC";
            }
            return "Not ABC";
        }
Posted

It will be the URL at which your WCF application is being hosted and run at. You should have added that to the ServiceHost object of your hosting application.

Please make sure, that you will only be able to let your friend consume your WCF application if he can access that URL from his network too; if he's using the same network then you can give him localhost URL too, but if he will be accessing through some other network, then you will have to purchase a static IP address and you will have to redirect your traffic to that link.
 
Share this answer
 
Comments
mayank.bhuvnesh 2-Apr-15 13:31pm    
Please provide the solution for the same as it is very urgent. I have posted the web.config file in.the solution please check that.
Url will be http://localhost:8080/applicationname/Service1.svc?name=input just replace my applicationname from your application name on IIS

OR

Click on your application(left pane) on IIS which you have hosted, then click on Browse(right pane), then browse your service on any compatible browser.

 
Share this answer
 
Comments
mayank.bhuvnesh 2-Apr-15 13:30pm    
Hi Rajat

Please provide the solution for the same as it is very urgent. I have posted the web.config file in.the solution please check that.
Rajat_RJT 3-Apr-15 1:38am    
I have updated the solution. Please check with that solution.
XML
Hi Sorry for the delayed response

Nothing is displayed on the page when I call the url

http://localhost/TestService/Service1.svc?name=ABC

I am hosting the service in IIS Server.
What I am missing here??? I have gone through the document shared by Upendar.

Since I have hosted the service in IIS, Do I have to use the ServiceHost

I am using the below WEB.Config file

<pre>

<configuration>
  <system.servicemodel>
    <behaviors>
      <servicebehaviors>
        <behavior name="mexBehaviour">
          <servicemetadata httpgetenabled="true" />
        </behavior>
      </servicebehaviors>
    </behaviors>
    <services>
      <service name="TestService.Service1" behaviorconfiguration="mexBehaviour">
        <endpoint address="http://localhost/TestService/Service1.svc" binding="basicHttpBinding" contract="TestService.IService1" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseaddresses>
            <add baseaddress="http://localhost/TestService/Service1.svc" />
          </baseaddresses>
        </host>
      </service>
    </services>
  </system.servicemodel>
  <system.web>
    <compilation debug="true" />
  </system.web>
</configuration>
 
Share this answer
 
As you are working with REST based service, change your web.config like below-
<configuration>
  <system.servicemodel>
    <behaviors>
      <servicebehaviors>
        <behavior name="mexBehaviour">
          <servicemetadata httpgetenabled="true" />
        </behavior>
      </servicebehaviors>
    <endpointbehaviors>
        <behavior name="endPtBehaviour">
          <webhttp />
        </behavior>
      </endpointbehaviors>
    </behaviors>
    <services>
      <service name="TestService.Service1" behaviorconfiguration="mexBehaviour">
        <endpoint address="" binding="webHttpBinding" behaviorconfiguration="endPtBehaviour" contract="TestService.IService1" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseaddresses>
            <add baseaddress="http://localhost/TestService/Service1.svc" />
          </baseaddresses>
        </host>
      </service>
    </services>
  </system.servicemodel>
  <system.web>
    <compilation debug="true" />
  </system.web>
</configuration>
 
Share this answer
 
Comments
mayank.bhuvnesh 3-Apr-15 2:39am    
Hi Rajat
Thanks for the reply
Now when I run the below URL

http://localhost/TestService/Service1.svc?name=ABC

its showing the wsdl document, where as it should display the result as per below method

public string checkName(string name)
{
if (name == "ABC")
{
return "ABC";
}
return "Not ABC";
}

The result should be ABC??

What I am missing here.
Rajat_RJT 3-Apr-15 5:22am    
Ok, i got it. Change UriTemplate = "/name={name}" and then call the url http://localhost/TestService/Service1.svc/name=ABC . This will absolutely work fine.
mayank.bhuvnesh 3-Apr-15 9:00am    
Rajat in a URL parameters are always declared after '?' not after '/'
Rajat_RJT 6-Apr-15 1:37am    
yes but in that case you need to give some name like http://localhost/TestService/Service1.svc/myservice?name=ABC then your URI template will be like - UriTemplate = "myservice?name={name}"
Read this tutorial..

http://wcftutorial.net
 
Share this answer
 
v2
Comments
mayank.bhuvnesh 2-Apr-15 13:32pm    
Please provide the solution for the same as it is very urgent. I have posted the web.config file in.the solution please check that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900