views:

2372

answers:

6

Hi there, I'm trying to built a SharePoint Web Part that has as part of it a service reference to Another SharePoint server that I need to call from within vb code. However when I try to call the remote web service for the first time, I get the following in the log:


Could not find default endpoint element that references contract 'ListReference.ListsSoap' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element. at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName) at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName) at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address) at System.ServiceModel.ChannelFactory1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress) at System.ServiceModel.EndpointTrait1.CreateSimplexFactory() at System.ServiceModel.ClientBase1.CreateChannelFactoryRef(EndpointTrait1 endpointTrait) at System.ServiceModel.ClientBase1.InitializeChannelFactoryRef() at System.ServiceModel.ClientBase1..ctor() at VSeWSS.ChangeRequestWorkflow.ChangeRequest.SubmitForm(Object sender, EventArgs e)


What is the proper way to deploy a Web Part with a Service Reference, could I be doing something wrong? Thanks!

+2  A: 

You need to add the endpoint configuration into the web.config of the SharePoint site that is consuming the webservice.

It worked for me, first time, but I was guessing as to how much of the web.config to copy. The endpoint is in a section <system.serviceModel><bindings><basicHttpBinding>...</bindings><client><endpoint>...</endpoint></client>...</system.serviceModel>. My SharePoint web.config didn't have a <system.serviceModel> element, so I added the whole element, from <system.serviceModel> down.
Javaman59
A: 

Hi, I have got the same error, I have my app.config well configured, I tried many time to remove and reinstall the web service.. I have set the security settings to TransportCredentialOnly. But the application keeps throwing that exception when I have a new ListsSoapClient(). Would you know any way to solve my problem?

A: 

Actually I solved my problem. My application has many projects, and the config file was in the project calling the WebService, but it seems it has to be in the starting project...

A: 

Hi,

Sorry to necro this; but does anyone know a way to get around this without using a Web.Config file ?

I've tried passing an endpoint name and address programatically but it fails with the same error.

Russ C
A: 

Hm, if I'm understanding what you're asking correctly, I'm doing that. I just added the webservice from one of the correct endpoints to the project in VS, then before I call it in my actual code, I get the URL I want to connect to with this call from the hierarchical object store from Codeplex, then set the Url property. So:

MyService srv = new MyService();
srv.Url = SPContext.Current.Web.Properties["serviceurl"];

Its working like that fine. hth.

mezmo
Hi Mezmo - That's the first thing I tried unfortunately :(The actual 'new Service(...)' ctor fails with the error message in the op: 'Could not find default endpoint element that references contract...'.Sadly, also the MSDN docs say that the ClientBase needs configuration values. This is an issue for us, as we don't want to expose this clients wsdl details to other users of our main product.
Russ C
+1  A: 

I found this question that solved my problem. Basically, I just needed to create a BasicHttpBinding object and populate its properties with the ones the SVC generator made in my app.config.

http://stackoverflow.com/questions/54579/wcf-configuration-without-a-config-file

Russ C