Computer
Computer

Reputation: 2227

The remote server returned an error: NotFound WCF Service

Windows Phone 8, Windows 8 + updates 64 bit, VS 2012. Running VS2012 as an admin

I have created a WCF service. Code on the service:

    [OperationContract]
    Object GetCustomersObject();

Implementation code

    public Object GetCustomersObject()
    {
        object c = DataContext.Customers;
        return c;
    }

I then Add a New Website to my application and configure the Service.svc file to point to the contract etc. Run it in a web browser and can see the WSDL.

I then test it using the WCFTestClient utility but i can connect to all the methods except for the one above as it does not support an Object.

I now create a Win Phone 8 project and connect to the service i then get the error "An exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.ni.dll but was not handled in user code"

expanding the exception i notice the message is The remote server returned an error: NotFound.. I then follow the steps found at http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj684580(v=vs.105).aspx since i am running IIS under VS i dont follow instructions for anything else (that is i add an entry to the config as suggested and open the firewall port, delete the existing service and readd it after shutting down the IIS service).

I still get the same error. So i delete the service and re-add it using the IP, machine name and whichever ive used still gives the same error.

I have also tried to turn the Windows Firewall service off to eliminate it being a firewall issue and same problem remains.

Im lost as to what else i could try?

Upvotes: 0

Views: 7853

Answers (2)

Falki
Falki

Reputation: 11

You typically see a CommunicationException because the app can’t find the web service at localhost.

Here is the solution for the same it might work

https://msdn.microsoft.com/library/windows/apps/jj684580%28v=vs.105%29.aspx

Upvotes: 1

nvoigt
nvoigt

Reputation: 77285

Sadly, "NotFound" does not mean that the service was actually not found. It's IIS' way to tell you "something failed".

Most likely, the failure occurs because you don't have a KnownType or ServiceKnownType attribute on your service or service interface although you need one.

The serializer of WCF is not omniscient. It looks at your function signature and serializes exactly that. Your signature says you return an object. Returning anything but null or new object() will irritate the serializer and make your service call fail. If you want to serialize something that is not a basic framework type and is not visible from the methods signature, you need to put a KnownType attribute with that type on your service class or a ServiceKnownType attribute on your interface to let the DataContractSerializer know what's coming.

Example:

[ServiceContract]
[ServiceKnownType(typeof(YourCustomer))]
public interface IYourService
{
    [OperationContract]
    Object GetCustomersObject();
}

Upvotes: 1

Related Questions