-
Notifications
You must be signed in to change notification settings - Fork 562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Null Return, when WCF Client [.Net8.0] communicate to WCF Server [.Net Framework 4.8] #5699
Comments
What do you mean when you say "I've got always null return instead of the expected data container"? This will require adding some instrumentation and/or attaching a debugger to understand what's going on. Knowing more precisely what you are experiencing will help to narrow down what steps you can take to get more information. Are you experiencing the null on the service side or the client? Are you able to attach a debugger while running your app in the problem environment? If so, are there are exceptions which are thrown and handled so that your code doesn't get exposed to them? |
I'm sorry. I can't debug here. This is customer land 😊. May this code sample explains a littlebit more: SampleDataContainer.cs: [DataContract]
public class SampleDataContainer {
[DataMember]
public List<string> SomeData { get; set; }
[DataMember]
public List<DatabaseModel> SomeMoreData { get; set; }
} IServiceContract.cs: [ServiceContract(Namespace = "http://mycompany.intranet.int",
Name = "myService",
CallbackContract = typeof(IServiceContractCallback))]
public interface IServiceContract {
[FaultContract(typeof(BusinessFault))]
[OperationContract]
SampleDataContainer FetchSomeData();
// All methods exists twice as sync/async
[FaultContract(typeof(BusinessFault))]
[OperationContract]
Task<SampleDataContainer> FetchSomeData_async();
} ServerImpl.cs: public class ServerImpl : IServiceContract {
public Task<SampleDataContainer> FetchSomeData_async()
=> Task.FromResult(FetchSomeData());
public SampleDataContainer FetchSomeData()
=> new SampleDataContainer() {
SomeData = new List<string> { "some", "sample", "data" },
SomeMoreData = LoadDataFromDB()
};
private List<DatabaseModel> LoadDataFromDB() {
// some deeper code; returns rows from DB
}
} ServiceContractCallback.cs: public interface IServiceContractCallback {
[OperationContract(IsOneWay = true)]
void SendMessage(CallbackMessageData messageData);
}
[CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant, UseSynchronizationContext = false)]
public class ServiceContractCallbackClientImpl : IServiceContractCallback {
// ...
} MyClientApp.cs: IServiceContract service = CreateServiceClient();
SampleDataContainer data = await service.FetchSomeData_async();
// This is where problem kicks in. All calls before are fine. data is null. The server does always return something, but the client didn't receive it
if (data == null || data.SomeData == null || data.SomeMoreData == null)
// BOOM🧨
throw new NullReferenceException($"data == null: {data == null}; data.SomeData == null: {data?.SomeData == null}; data.SomeMoreData == null: {data?.SomeMoreData == null}");
// The error output is:
// data == null: True; data.SomeData == null: True; data.SomeMoreData == null: True
public IServiceContract CreateServiceClient(string url = "net.tcp://localhost:8089")
=> MyServiceClient(url, "netTcpBinding", new ServiceContractCallbackClientImpl()); |
Before we get into your problem, I just wanted to explain to you the whole sync vs async thing in the contract interface as you're doing something a little unusual and you might be able to improve/cleanup your code a little. Unrelated to your problem, but wanted to mention it. Whether the operation is sync or async doesn't change anything sent or received over the wire. This means you can have your server side operation be synchronous while having the client be async, or vice versa. There is a default action and reply action value generated which is based off the method name. If your method is synchronous and called Foo, it will have the same action value generated as an async method call FooAsync. If an operation method returns Task or Task<T>, then it removes any trailing Async from the name before generating the action, which results in the same action name. What this means is on the client side you can declare two methods, Foo and FooAsync, and as long as they have the same list of parameters and return the same type (with the async version having the return value wrapped in a Task), then they will dispatch to the same operation on the service side. So you can offer a Foo and FooAsync method on your client side contract interface so the client can decide whether to call your operation synchronously or asynchronously, and they will dispatch to a single service side method. You can't declare both on the service side contract because WCF wouldn't know whether to dispatch the call to the synchronous implementation or the async implementation as they are identical from a SOAP message standpoint. Anyway, on to your problem. Having a null value returned means the XML being returned isn't matching what is expected. In the response, there will be a wrapping response XML element, probably called Are you able to provide your customer with a custom build of your app which has some extra instrumentation added, and then collect some logs and have them send you the log file? If so, I can show you how to capture the XML SOAP message in a text form and you can then use that any way which makes sense to you (write to file, put into zip file etc). |
Describe the bug
When I call an async method on my service it works in most environments. But in one system (productive) I've got always null return instead of the expected data container. It makes no different which method I'll call. All of them return null. No exceptions when calling. Same code on both installations (dev and production).
Additional context
Please help! I can't see the error.
The text was updated successfully, but these errors were encountered: