views:

14756

answers:

16

I've added a proxy to a webservice to a VS2008/.NET 3.5 solution. When constructing the client .NET throws this error:

Could not find default endpoint element that references contract 'IMySOAPWebService' in the service model client configuaration section. This might be because no configuaration file was found for your application or because no end point element matching this contract could be found in the client element

Searching for this error tells me to use the full namespace in the contract. Here's my app.config with full namespace:

<client>
  <endpoint address="http://192.168.100.87:7001/soap/IMySOAPWebService"
            binding="basicHttpBinding" bindingConfiguration="IMySOAPWebServicebinding"
            contract="Fusion.DataExchange.Workflows.IMySOAPWebService" name="IMySOAPWebServicePort" />
</client>

I'm running XP local (I mention this because a number of Google hits mention win2k3) The app.config is copied to app.exe.config, so that is also not the problem.

Any clues?

A: 

If this is running on a web server then you need to add .svc. Example: "http://192.168.100.87:7001/soap/IMySOAPWebService.svc

Darren C
The service is an not a .NET service, it is not running on a webserver.
edosoft
A: 

I think that it usually references by name, so in your example the name that you have is 'IMySOAPWebServicePort' and not 'IMySOAPWebService'. You may have a mismatch somewhere...

MattK
+5  A: 

Having tested several options, I finally solved this by using

contract="IMySOAPWebService"

i.e. without the full namespace in the config. For some reason the full name didn't resolve properly

edosoft
+2  A: 

The namespace in your config should reflect the rest of the namespace path after your client's default namespace (as configured in the project properties). Based on your posted answer, my guess is that your client is configured to be in the "Fusion.DataExchange.Workflows" namespace. If you moved the client code to another namespace you would need to update the config to match the remaining namespace path.

Chris Porter
+2  A: 

I had the same problem, but changing the contract namespace didn't work for me. So I tried a .Net 2 style web reference instead of a .Net 3.5 service reference. That worked.

To use a Web reference in Visual Studio 2008, click on 'Add Service Reference', then click 'Advanced' when the dialog box appears. In that you will find an option that will let you use a Web reference instead of a Service reference.

Cyril Gupta
This is what I ended up doing as well. I wish the problem made sense to me.
jarrett
This worked for me, also. Now I have all this extra junk in my solution (Settings.Settings, a new Web References folder) for no good reason. Will have to come back and re-visit this when I have more time.
Mike at KBS
Agreed. I had the same problem, and fixed it by changing it to a web reference.
Javaman59
A: 

I had the same problem, and gave up on trying to figure why the name would not resolve. It ended up being easier to just write code to create the binding instead of using the app.config. The code is similar to that found here.

dan9298
+2  A: 

This one drove me crazy.

I'm using Silverlight 3 Prism (CAB) with WCF

When I call a WCF service in a Prism module, I get the same error:

"Could not find default endpoint element that references contract 'IMyService' in the service model client configuaration section. This might be because no configuaration file was found for your application or because no end point element matching this contract could be found in the client element"

It turns out that its looking in the Shell's .xap file for a ServiceReferences.ClientConfig file, not in the module's ServiceReferences.ClientConfig file. I added my endpoint and binding to the existing ServiceReferences.ClientConfig file in my Silverlight Shell application (it calls it's own WCF services).

Then I had to rebuild the Shell app to generate the new .xap file for my Web project's ClientBin folder.

Now this line of code finally works:

MyServiceClient myService = new MyServiceClient();

Jeff Moeller
This was true in my case too. Thanks.
Raj
Me too... but don't know why it was not there in the first place...
devMomentum
A: 

This error can arise if you are calling the service in a class library and calling the class library from another project.

Manuel Alves
+19  A: 

"This error can arise if you are calling the service in a class library and calling the class library from another project."

In this case you will need to include the WS configuration settins into the main projects app.confing if its a winapp or web.config if its a web app. This is the way to go even with PRISM and WPF/Silverlight.

L.R.
This is why I was having trouble - thanks
Calanus
This wasn't the cause for my specific problem, but I'm sure this will help others. Thanks
edosoft
Thanks, this helped me :)
Rachel
Keep coming across this error and keep coming across this answer - if only I could up-vote twice!
David A Gibson
+1 !! Drove me totally crazy and yes, it was the problem....
Juri
A: 

There seem to be several ways to create/fix this issue. For me, the CRM product I am using was written in native code and is able to call my .NET dll, but I run into the configuration information needing to be at/above the main application. For me, the CRM application isn't .NET, so I ended up having to put it in my machine.config file (not where I want it). In addition, since my company uses Websense I had a hard time even adding the Service Reference due to a 407 Proxy Authentication Required issue, that to required a modification to the machine.cong.

Proxy solution:

To get the WCF Service Reference to work I had to copy the information from the app.config of my DLL to the main application config (but for me that was machine.config). And I also had to copy the endpoint information to that same file. Once I did that it starting working for me.

Droo
+5  A: 

I've had this same issue. It turns out that for a web REFERENCE, you have to supply the URL as the first parameter to the constructor:

new WebService.WebServiceSoapClient("http://myservice.com/moo.aspx");

For a new style web SERVICE REFERENCE, you have to supply a name that refers to an endpoint entry in the configuration:

new WebService.WebServiceSoapClient("WebServiceEndpoint");

With a corresponding entry in Web.config or App.config:

<client>
      <endpoint address="http://myservice.com/moo.aspx"
        binding="basicHttpBinding" 
        bindingConfiguration="WebService"
        contract="WebService.WebServiceSoap"
        name="WebServiceEndpoint" />
    </client>
  </system.serviceModel>

Pretty damn hard to remove the tunnel vision on "it worked in an older program"...

Andomar
+1  A: 

I Have a same Problem.I'm Used the WCF Service in class library and calling the class library from windows Application project.but I'm Forget Change <system.serviceModel> In Config File of windows application Project same the <system.serviceModel> of Class Library's app.Config file.
solution: change Configuration of outer project same the class library's wcf configuration.

sAeid mOhammad hAshem
A: 

Ok. My case was a little diffrent but finally i have found the fix for it: I have a Console.EXE -> DLL -> Invoking WS1 -> DLL -> Invoking WS2

I have had both the configurations of the service model of WS1, and WS2 in the Console.EXE.config as recommended. - didnt solve the issue.

But it still didn't work, until i have added the WebReference of WS2 to WS1 also and not only to the DLL that actually creating and invoking the proxy of WS2.

Itay Levin
A: 

Just for anyone else with the same problem; I wrote a unit test for my method that tried to connect to my service. It failed with this same exception every time - I have no idea why. When I ran it from a winform it works fine.

PhilG
A: 

If u reference the web service in u r class library then you have to copy app.config to your windows application or console application

solution: change Configuration of outer project same the class library's wcf configuration.

Worked for me

+1  A: 

I found (as well as copying to the client UI's App.config as I was using a Class Library interface) I had to prefix the name of the binding with the name of the Service Reference (mine is ServiceReference in the below).

e.g.:

<endpoint address="http://localhost:4000/ServiceName" binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_ISchedulerService"
      contract="ServiceReference.ISchedulerService" 
      name="BasicHttpBinding_ISchedulerService" />

instead of the default generated:

<endpoint address="http://localhost:4000/ServiceName" binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_ISchedulerService"
      contract="ISchedulerService" 
      name="BasicHttpBinding_ISchedulerService" />
Graphain