1

I have a very strange problem. I have a working WCF service.

[ServiceContract]
public interface IService
{
    [OperationContract]
    int AddResult(int result, string name);

    [OperationContract]        
    int list(int count);
}

In another class I have the implementation of this service. And it works. But when I change the method "list" like this:

[ServiceContract]
public interface IService
{
    [OperationContract]
    int AddResult(int result, string name);

    [OperationContract]        
    List<string> list(int count);        
}

When I add service reference from targeted project (it is a Windows Phone application) I receive several errors and warnings. The key idea of them is that the service cannot be loaded (or endpoints can not be loaded). The difference between two methods is very small - List instead of int type. But it is crucial. Why it is so? Why I can not use List?

user1460819
  • 2,052
  • 5
  • 26
  • 35

1 Answers1

1

did you try to encapsulate your List collection into a proxy class? You could try something like:

[DataContract]
public class MyData
{
    [DataMember]
    public List<string> list { get; set; }
}

[ServiceContract]
public interface IService
{
    [OperationContract]
    int AddResult(int result, string name);

    [OperationContract]        
    MyData list(int count);        
}

Also, take a look at this link, I think that it might be what you are looking for.

UPDATE

As per discussed on the comments section of this thread, the problem was not located in the WCF service itself, but on the client that was being generated in @user1460819 Windows Phone app.

This problem was solved after the WCF Service binding was changed to "basicHttpBinding", the WCF reference on the client side was regenerated and the whole project was rebuilt.

Community
  • 1
  • 1
Felipe
  • 6,312
  • 11
  • 52
  • 70
  • One of the warnings is: "Custom tool warning: Exception has been thrown by the target of an invocation. C:\Documents\Visual Studio 2010\Projects\project\project\Service References\ServiceReference1\Reference.svcmap" – user1460819 Jun 18 '12 at 18:55
  • Another warning is "Custom tool warning: No endpoints compatible with Silverlight 3 were found. The generated client class will not be usable unless endpoint information is provided via the constructor. C:\Documents\Visual Studio 2010\Projects\project\project\Service References\ServiceReference1\Reference.svcmap" – user1460819 Jun 18 '12 at 19:17
  • And a very important fact (I noticed several minutes ago) is that from Console Application I may use my WCF Service without any errors, but in Windows Phone Application several errors exist. – user1460819 Jun 18 '12 at 19:34
  • Well, then I suppose that your error should be in the Windows Phone app... What are you using to connect to the WCF service in your mobile app? Is it a Microsoft API? Chances are that even if you are using a Microsoft API in your app, it doesn't support those fancy WCF bindings like: wsHttpBinding. If you are using this binding (or any other binding), try changing it to: basicHttpBinding. – Felipe Jun 18 '12 at 19:45
  • Also, to the extent of my knowledge nothing outside of Microsoft supports any other binding other than basicHttpBinding. So If you want compatibility, you should stick to this binding. Here is a quick tour of bindings in WCF: http://wcftutorial.net/WCF-Types-of-Binding.aspx. – Felipe Jun 18 '12 at 19:47
  • Here is the link, where all the warnings can be seen https://docs.google.com/open?id=0B0hJreYFzXldRGdldEh4ck8xazg – user1460819 Jun 18 '12 at 19:49
  • Where should I change wsHttpBinding to basicHttpBinding? – user1460819 Jun 18 '12 at 19:50
  • I changed it in App.config file (WCF Service Library) but I still doesn't work – user1460819 Jun 18 '12 at 19:57
  • Please note that after changing the binding type, you need to re-deploy your service and update your client's bindings. Did you do that? – Felipe Jun 18 '12 at 20:03
  • I rebuilt the WCF project, launched it again, updated the service reference, but it doesn't work – user1460819 Jun 18 '12 at 20:08