views:

124

answers:

3

I've added as wsdl file using the add servece reference dialog in vs2008.

MyService serviceproxy = new MyService();

When I instantiate the service proxy, I get an InvalidOperationException with the following text (translated from german):

Could not find default endpoint element to the contract "ServiceName.ServiceInterface" in the service model refers client configuration section. This may be because: The application configuration file was not found or not an endpoint in the client element item is found, which corresponded to this contract.

Where servicename is the name I give the service when I add it in vs2008 and ServiceInterface the interface which is automatically generated for it.

EDIT here is what's in my app.config:

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="MyServiceBinding" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
    </system.serviceModel>
+1  A: 

Check your config file - web.config if you're in a ASP.NET web app or web site, app.config if it's a Winforms or console app.

There ought to be some config for your WCF service in there - anything below <system.serviceModel> would be fine. If not - add the necessary info to your config!

OK, so if you want to specify your endpoint URL in code, you need to do this when you instantiate your client proxy class - otherwise, it'll go look in config. Using this code snippet, you'll be using the http binding configuration settings from app.config, and specify the URL separately, in code:

BasicHttpBinding binding = new BasicHttpBinding("MyServiceBinding");
EndpointAddress address = new EndpointAddress(new Uri("http://localhost:8888/YourService"));

MyService serviceproxy = new MyService(binding, address);

That way, the basicHttpBinding object will read the settings from the config under the bindings with a name=MyServiceBinding.

marc_s
I've updated my question with the contents of my app.config. But note that I plan to specify the service url in code and not in config because the url is user input.
codymanix
this way you completely ignore whats in the config file. And it still doesn't know about the contract.
the_ajp
@marc_s You still have to specify the contract. Even in code if you want. He only says he wants to specify the uri in code.
the_ajp
@the_ajp: the contract is implied, by means of using the "MyService" client proxy class, which has been creating using Add Service Reference. No need to specify the contract *again*.
marc_s
@marc_s: I didn't know the contract would be implied. But that's true indeed.
the_ajp
+1  A: 

You need something like this in your config:

<client>
  <endpoint binding="basicHttpBinding" 
    bindingConfiguration="MyServiceBinding" contract="ServiceName.ServiceInterface"
    name="MyServiceEndpoint">
  </endpoint>
</client>

inside your tag

I just read your comment.

So Removed the address from the endpoint config.

You can choose to specify the endpoint completely in your code or just the address like this:

MyServiceClient proxy = new MyServiceClient();
proxy.Endpoint.Address = new EndpointAddress ("http://addressto your service"); //<-- address
the_ajp
@marc_s: where it says : contract="ServiceName.ServiceInterface"
the_ajp
+1  A: 

Edit: Sorry, my first answer was wrong. For the client you need:

ChannelFactory<Interface> factory = new ChannelFactory< YourServiceInterface >(new basicHttpBinding(), new EndpointAddress(new Uri("http://localhost:8888/YourService")));
YourServiceInterface proxy = factory.CreateChannel();
Flo