Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why WCF cannot be invoked in wcftestclient?

Tags:

wcf

I built up a WCF service, it works good in IE addr, but once i add it to wcftestclient and invoke a method, an error was prompted and shown as :

Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.

Error Details:

The Address property on ChannelFactory.Endpoint was null.  The ChannelFactory's Endpoint must have a valid Address specified.
   at System.ServiceModel.ChannelFactory.CreateEndpointAddress(ServiceEndpoint endpoint)
   at System.ServiceModel.ChannelFactory`1.CreateChannel()
   at System.ServiceModel.ClientBase`1.CreateChannel()
   at System.ServiceModel.ClientBase`1.CreateChannelInternal()
   at System.ServiceModel.ClientBase`1.get_Channel()
   at MyDownloadSvcClient.DeleteMyFolder(Int32 UserId, Int32 FolderId)

The config file is: (updated at 10/9)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <services>
            <service name="MyDownloadSvcClient">
                <endpoint binding="basicHttpBinding" />
            </service>
        </services>
        <bindings />
        <client>
            <endpoint address="http://localhost/MyDownloadSvc.svc"
                binding="basicHttpBinding" bindingConfiguration="" contract="IMyDownloadSvc"
                name="Test" />
        </client>
    </system.serviceModel>
</configuration>

Is there anything wrong?

Thanks in advance, Elaine

like image 732
Elaine Avatar asked Oct 08 '10 08:10

Elaine


3 Answers

Yes, there's definitely something wrong. A service endpoint WCF must always supply the ABC - Address, Binding, Contract. You only define the binding in your config - and that's exactly what the error message says - your address is null.

So your config fragment should look something like:

<system.serviceModel>
    <services>
        <service name="MyDownloadSvcClient">
            <endpoint 
                address="http://localhost:8888/YourService"
                binding="basicHttpBinding"
                contract="IYourServiceContract" />
        </service>
    </services>

The Address defines where the service endpoint lives, at what address it's available to the outside world. If you have no address, then the service cannot talk to the outside where. It's there WHERE of your service. If you host your service in IIS, using a *.svc file, you might be leaving this address empty, since the service address is determined by the server and virtual directory where the *.svc file lives - but you still need to supply an address="" entry to your service <service>/<endpoint> tag!

The Binding defines how the service interacts - what protocol, what security settings etc. - it's the HOW of your service.

And the Contract in the end defines (through a service contract, typically an interface in your service definition) what service methods (functions) are available to a caller. You must supply a contract, otherwise the caller has no way of knowing what methods he can call on your service. It's the WHAT of the service.

like image 192
marc_s Avatar answered Nov 03 '22 02:11

marc_s


Your service works from IE and your binding name on client after creating service reference starts with WebHttpBinding_. So you are using REST service, aren't you? Such service cannot be added as service reference and such service is not supported in WcfTestClient.

like image 25
Ladislav Mrnka Avatar answered Nov 03 '22 01:11

Ladislav Mrnka


I had this error and I was able to create a .svclog file and see the actual error (it was from my IOC container... coding mistake I didn't register a class with my IOC)

See the article on MDSN for how to create a .svclog file and view it: https://msdn.microsoft.com/en-us/library/ms732023.aspx

like image 43
tjp69 Avatar answered Nov 03 '22 02:11

tjp69