Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have created a SharePoint feature that has an application page which uses a wcf service to get some data. I have added a service reference to the WCF service using vs2010 service reference options. At the moment I have hard coded the service url (for ex., http://localhost:2000/vti_bin/service1.svc) and passing the url to the proxy.

When I add the service reference it also creates app.config which contains the necessary service bindings settings. When I deploy the feature how does the application page use service bindings and do I need to manually add the Service URL and Service Bindings settings to the web.config file for each web application.

What is the recommended approach to reference a WCF service in a application page?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

You can consume WCF in configless way by providing the necessary settings programmatically. Below is an example when using WSHttpbinding with relevant settings:

            WSHttpBinding bind = new WSHttpBinding(SecurityMode.None);
            bind.MaxBufferPoolSize = 2147483647;
            bind.MaxReceivedMessageSize = 2147483647;
            EndpointAddress endpoint = new EndpointAddress(new Uri(serviceURL));

serviceClient=new serviceClient(bind, endpoint);

The second option is to create a new folder for your application page and convert it to virtual directory. Here, You can place a custom web.config with just the service settings you need.

share|improve this answer
    
Thanks Amit... Do I need to copy the ServiceURL to the web.config file of each web application? At present I have hardcoded the service URL in application page. –  Kannan Dec 13 '11 at 23:20
    
You can keep the url in the same web.config as I mentioned above. No need to do it for separate web applications then. –  Amit Kumawat Dec 14 '11 at 17:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.