Question

I am writing a WCF service that will be called by a proprietary WebService (asmx). I only have access to a very brief documentation and a test tool used to verify WCF service functionality. Test tool fails with: Object reference not set to an instance of an object.

There is one method, GetBalance, that supplies a class as an input parameter to WCF:

class ClientRequest
{
int ClientID,
string Currency,
datetime AsOfDate
}  

And expects return:

class ClientResponse
{
int ClientID,
decimal Balance
}  

That’s all I have in doc’s.
Other methods with simple data types work just fine.
After some research I narrowed down the issue to the difference in the SOAP XML between simple and complex input data types:
Simple (snippet):

<soap:Envelope xmlns:soap="h t t p ://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="h t t p : / / www.w3.org/2001/XMLSchema-instance" xmlns:xsd="h t t p : / /www.w3.org/2001/XMLSchema">
<soap:Body>
    <GetUserDetails xmlns="h t t p : / /t e m p u r i . o r g/">
        <UserID>12345</UserID>

…..

Complex (snippet):

<soap:Envelope xmlns:soap="h t t p ://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="h t t p : //www.w3.org/2001/XMLSchema-instance" xmlns:xsd="h t t p ://www.w3.org/2001/XMLSchema">
<soap:Body>
    <GetBalance xmlns="h t t p ://tempuri.org/">
        **<request>**
            <ClientID>645</ClientID>

……

In my WCF code:

[ServiceContract (Namespace="h t t p : //tempuri.org/")]    
public interface IClientAPI
{
 [OperationContract(Action = " h t t p : //tempuri.org/GetBalance", ReplyAction = "h t t p ://tempuri.org/GetBalance")]
 ClientResponse GetBalance(ClientRequest clientrequest);
}  

[DataContract(Namespace = "h t t p ://tempuri.org/"), Serializable]
public class ClientRequest
{
 [DataMember]
 public int ClientID { get; set; }
 [DataMember]
 public string Currency { get; set; }
 [DataMember]
 public datetime AsOfDate { get; set; }
}

……………..

[DataContract(Namespace = "http://t e m p u r i . o r g/")]
public class ClientResponse
{
 [DataMember]
 public int ClientID { get; set; }
 [DataMember]
 public decimal Balance { get; set; }

 public static ClientResponse GetBalance(ClientRequest clientrequest)
 {
   //DO STUFF
    return response;
  }
}

Service:

public ClientResponse GetBalance(ClientRequest clientrequest)
        {
            ClientResponse r = new ClientResponse();
            int i = ClientResponse.GetBalance(clientrequest);
            //DO STUFF
        return r;
    }

Input clientrequest here always is NULL.
Clearly it has something to do with tag in SOAP input.
Any further clues, ideas, articles would be very much appreciated. The error in the GetBalance method is: Object reference not set to an instance of an object. ClientRequest is null.
Thank you very much.
Ed

Was it helpful?

Solution

After few days I found the solution (documentation was a bit off):
A parameter name must match the SOAP XML tag that follows the method name (as shown in the Complex (snippet): above). In this case instead of calling/using:

{  
    ClientResponse GetBalance(ClientRequest clientrequest);  
}  

it should be:

{  
    ClientResponse GetBalance(ClientRequest request);  
}  
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top