문제

I created a WCF service (.NET 3.5) that grabs data from a db and returns a list of objects. It works just fine. I tested it using the WCFTestClient application and got the desired results.

Now, I tried to create an ASP.NET web application and consume the service. After enabling <serviceDebug includeExceptionDetailInFaults="true"/> in the config file, the error message is "Object reference not set to an instance of an object."

How do I modify the service to work with ASP.NET?

Thanks!

Update 1 - I created a reference to the service. When I ran my very basic testing app, based on the sample code displayed on the service's default web page, I got the "Object reference not set to an instance of an object" message.

The service is returning the correct results when I use the WCF Test Client utility provided with Visual Studio. When I try to use the following code, all in the page_load event, I get the object reference message.

PhoneNumberServiceClient client = new PhoneNumberServiceClient();

// Use the 'client' variable to call operations on the service
List<PhoneNumber> phones = client.GetPhoneNumbers();  

// Always close the client.
client.Close();

I will try to get some additional debug info.

도움이 되었습니까?

해결책

Have you tried openning the service after you initialize it by using:

client.Open();

If the problem still persists maybe the it lies on the WCF method itself. Try to add breakpoints on your method and debug it to trace the cause of the error. You could also use profilers.

다른 팁

You also have to configure the Service to allow exception details in results. Follow the info in here to make that happen.

I presume your ASP.NET app is expecting to catch certain information from the service that you have not set it up to provide, hence the null object error.

I would have written this as comment, but couldn't figure out how to, so I guess I'll attempt an answer.

You mentionned you used the built in test client, but when You created your client application(the website that you want to be calling your new service with) have you configured it's end point(web.config) to match the end of your wcf service? For example, a client app calling a wcf service with wsHttpBinding endpoint:

<configuration>
<system.serviceModel>
    <client>
        <endpoint address="http://localhost:8080/ContractorService" binding="wsHttpBinding" contract="ContractorService.IContractorService"
            name="ContractorService_WsHttp">
        </endpoint>
    </client>
</system.serviceModel>

Also, your service is returning a list, the default service reference that you added to your client very likely stops at array. Right click the service reference your client now has and select configure service reference, in the drop down box for collection type, instead of System.array, select System.Collections.Generic.List.

If you need details on configuration, check here http://msdn.microsoft.com/en-us/library/dd936243.aspx

Place a break point in the Page_Load method of your client, you should be able to step through your client code and it will jump in automatically in your wcf service once you call it's method, then you can see exactly where it fails. Hope this helps

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top