开发者

Cannot connect to my WCF service right out of the box

I have a service I am trying to consume in a unit test. At this point I'm just trying to instantiate the thing. After suffering the "Could not find default endpoint element that references contract" error for hours and unable to figure it out, I completely deleted out the consumer and started from scratch. All I did was add a service reference to my test project, point it at my service, hit "GO" and that's it. Still doesn't work. I didn't touch a line of code, yet it doesn't work right after I let VS build the thing.

Here is the relevant line in my app.config for the test project:

<client>
    <endpoint address="http://mike-laptop/kbs/FFEDI/Service.svc"
       binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IEdiService"
       contract="ServiceReference2.IEdiService" name="BasicHttpBinding_IEdiService" />
</client>

In my unit test, here is my method:

public void CreateWebServiceInstance()
{
    ServiceRefer开发者_如何学Cence2.EdiServiceClient webService = new ServiceReference2.EdiServiceClient();
    string svcAddress = webService.Endpoint.Address.ToString();
    Console.WriteLine("Address is: " + svcAddress);
    Assert.IsTrue(svcAddress.Equals("http://mike-laptop/kbs/FFEDI/Service.svc"));  // test
}

The error I get is:

System.InvalidOperationException: Could not find default endpoint element that references contract 'ServiceReference2.IEdiService' 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.

Again, I didn't change anything this time. Any ideas?


Is the service hosted in IIS? Can you hit it in a browser? Do you have a <binding name="BasicHttpBinding_IEdiService">... in your config? Did you try passing the binding config name into the constructor?


Seems fine at first sight to me... some ideas to check / ponder / verify:

  • does your test project's app.config get read at all? E.g. is it being interpreted at all? Is there a TestProject.exe.config in your bin\debug directory? I'm thinking maybe the test runner might be playing some tricks and not reading the config at all.

  • or what happens if you specify the name of the client endpoint when creating your service client?

    ServiceReference2.EdiServiceClient webService = 
        new ServiceReference2.EdiServiceClient("BasicHttpBinding_IEdiService");
    

Does that change anything at all?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜